From 0395e8f7d73564eb762b5cef4b1602192891b62b Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Mon, 21 Jun 2021 15:00:40 +0200 Subject: [PATCH] libblkid: check errno after strto..() Addresses: https://github.com/karelzak/util-linux/issues/1356 Signed-off-by: Karel Zak --- libblkid/src/partitions/partitions.c | 3 ++- libblkid/src/probe.c | 4 ++++ libblkid/src/read.c | 17 +++++++++++++---- 3 files changed, 19 insertions(+), 5 deletions(-) diff --git a/libblkid/src/partitions/partitions.c b/libblkid/src/partitions/partitions.c index 611bf8e0a..a34a446dc 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 9adc4cf76..0427759dd 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 c3b41be76..d62edfae3 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));