From: Karel Zak Date: Mon, 21 Jun 2021 13:00:40 +0000 (+0200) Subject: libblkid: check errno after strto..() X-Git-Tag: v2.38-rc1~415 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=0395e8f7d73564eb762b5cef4b1602192891b62b;p=thirdparty%2Futil-linux.git libblkid: check errno after strto..() Addresses: https://github.com/karelzak/util-linux/issues/1356 Signed-off-by: Karel Zak --- diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c index 611bf8e0a1..a34a446dc6 100644 --- a/libblkid/src/partitions/partitions.c +++ b/libblkid/src/partitions/partitions.c @@ -1040,8 +1040,9 @@ blkid_partition blkid_partlist_devno_to_partition(blkid_partlist ls, dev_t devno if (prefix && strncasecmp(prefix, "part", 4) == 0) { char *end = NULL; + errno = 0; partno = strtol(prefix + 4, &end, 10); - if (prefix == end || (end && *end)) + if (errno || prefix == end || (end && *end)) partno = 0; else rc = 0; /* success */ diff --git a/libblkid/src/probe.c b/libblkid/src/probe.c index 9adc4cf763..0427759ddc 100644 --- a/libblkid/src/probe.c +++ b/libblkid/src/probe.c @@ -1332,7 +1332,11 @@ int blkid_do_wipe(blkid_probe pr, int dryrun) if (rc || len == 0 || off == NULL) return 0; + errno = 0; magoff = strtoumax(off, NULL, 10); + if (errno) + return 0; + offset = magoff + pr->off; fd = blkid_probe_get_fd(pr); if (fd < 0) diff --git a/libblkid/src/read.c b/libblkid/src/read.c index c3b41be765..d62edfae3f 100644 --- a/libblkid/src/read.c +++ b/libblkid/src/read.c @@ -297,16 +297,25 @@ static int parse_tag(blkid_cache cache, blkid_dev dev, char **cp) DBG(READ, ul_debug("tag: %s=\"%s\"", name, value)); + errno = 0; + /* Some tags are stored directly in the device struct */ - if (!strcmp(name, "DEVNO")) + if (!strcmp(name, "DEVNO")) { dev->bid_devno = strtoull(value, NULL, 0); - else if (!strcmp(name, "PRI")) + if (errno) + return -errno; + } else if (!strcmp(name, "PRI")) { dev->bid_pri = strtol(value, NULL, 0); - else if (!strcmp(name, "TIME")) { + if (errno) + return -errno; + } else if (!strcmp(name, "TIME")) { char *end = NULL; + dev->bid_time = strtoull(value, &end, 0); - if (end && *end == '.') + if (errno == 0 && end && *end == '.') dev->bid_utime = strtoull(end + 1, NULL, 0); + if (errno) + return -errno; } else ret = blkid_set_tag(dev, name, value, strlen(value));