]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libmount: 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:03:01 +0000 (15:03 +0200)
Addresses: https://github.com/karelzak/util-linux/issues/1356
Signed-off-by: Karel Zak <kzak@redhat.com>
libmount/python/pylibmount.c
libmount/src/context_veritydev.c
libmount/src/tab_parse.c

index 2e6bb62d7fb9b85a85395fe0a2fba5572bdd14a0..bfc100fe1d3f37e9f51ad9b222f85c888d3f251d 100644 (file)
@@ -220,9 +220,12 @@ PyMODINIT_FUNC initpylibmount(void)
        if (!(pylibmount_debug_mask & PYMNT_DEBUG_INIT)) {
                char *str = getenv("PYLIBMOUNT_DEBUG");
 
+               errno = 0;
                pylibmount_debug_mask = 0;
                if (str)
                        pylibmount_debug_mask = strtoul(str, NULL, 0);
+               if (errno)
+                       pylibmount_debug_mask = 0;
 
                pylibmount_debug_mask |= PYMNT_DEBUG_INIT;
        }
index e795c071c9a999e6428e9d07dec7221b6b414941..2878d9489c612ed4180e9dbc52feb6c99e57e6f9 100644 (file)
@@ -61,8 +61,9 @@ static size_t crypt_hex_to_bytes(const char *hex, char **result)
 
        for (i = 0; i < len; i++) {
                memcpy(buf, &hex[i * 2], 2);
+               errno = 0;
                bytes[i] = strtoul(buf, &endp, 16);
-               if (endp != &buf[2]) {
+               if (errno || endp != &buf[2]) {
                        free(bytes);
                        return -EINVAL;
                }
index 95585b5b785cf3ddc0cbb5d6ddda4b9f60560971..917779ab6d92d4362d0681646bfa229149072cc3 100644 (file)
@@ -50,11 +50,12 @@ static const char *next_s32(const char *s, int *num, int *rc)
        if (!s || !*s)
                return s;
 
+       errno = 0;
        *rc = -EINVAL;
        *num = strtol(s, &end, 10);
        if (end == NULL || s == end)
               return s;
-       if (*end == ' ' || *end == '\t' || *end == '\0')
+       if (errno == 0 && (*end == ' ' || *end == '\t' || *end == '\0'))
                *rc = 0;
        return end;
 }
@@ -66,11 +67,12 @@ static const char *next_u64(const char *s, uint64_t *num, int *rc)
        if (!s || !*s)
                return s;
 
+       errno = 0;
        *rc = -EINVAL;
        *num = (uint64_t) strtoumax(s, &end, 10);
        if (end == NULL || s == end)
               return s;
-       if (*end == ' ' || *end == '\t' || *end == '\0')
+       if (errno == 0 && (*end == ' ' || *end == '\t' || *end == '\0'))
                *rc = 0;
        return end;
 }