libblkid: check errno after strto..()

Addresses: https://github.com/karelzak/util-linux/issues/1356
Signed-off-by: Karel Zak <kzak@redhat.com>
This commit is contained in:
Karel Zak 2021-06-21 15:00:40 +02:00
parent 1293b0f65d
commit 0395e8f7d7
3 changed files with 19 additions and 5 deletions

View 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 */

View 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)

View 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));