]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libblkid: check errno after strto..()
authorKarel Zak <kzak@redhat.com>
Mon, 21 Jun 2021 13:00:40 +0000 (15:00 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 21 Jun 2021 13:00:40 +0000 (15:00 +0200)
Addresses: https://github.com/karelzak/util-linux/issues/1356
Signed-off-by: Karel Zak <kzak@redhat.com>
libblkid/src/partitions/partitions.c
libblkid/src/probe.c
libblkid/src/read.c

index 611bf8e0a18b3cfd3743e53a11e4e531a7d31b84..a34a446dc681c5fba4fe9579991709607330dce4 100644 (file)
@@ -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 */
index 9adc4cf76399125137d3b4cc60de59bf9de03e6a..0427759ddc4e664bdaef09f193bf21b5ab3a90ae 100644 (file)
@@ -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)
index c3b41be7656263beeaafa405d55035ee23961ac0..d62edfae3fc79b3812fcf21dfb85c7dcd428b796 100644 (file)
@@ -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));