libmount: 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:
parent
736b6ab7fd
commit
0729593862
|
@ -220,9 +220,12 @@ PyMODINIT_FUNC initpylibmount(void)
|
||||||
if (!(pylibmount_debug_mask & PYMNT_DEBUG_INIT)) {
|
if (!(pylibmount_debug_mask & PYMNT_DEBUG_INIT)) {
|
||||||
char *str = getenv("PYLIBMOUNT_DEBUG");
|
char *str = getenv("PYLIBMOUNT_DEBUG");
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
pylibmount_debug_mask = 0;
|
pylibmount_debug_mask = 0;
|
||||||
if (str)
|
if (str)
|
||||||
pylibmount_debug_mask = strtoul(str, NULL, 0);
|
pylibmount_debug_mask = strtoul(str, NULL, 0);
|
||||||
|
if (errno)
|
||||||
|
pylibmount_debug_mask = 0;
|
||||||
|
|
||||||
pylibmount_debug_mask |= PYMNT_DEBUG_INIT;
|
pylibmount_debug_mask |= PYMNT_DEBUG_INIT;
|
||||||
}
|
}
|
||||||
|
|
|
@ -61,8 +61,9 @@ static size_t crypt_hex_to_bytes(const char *hex, char **result)
|
||||||
|
|
||||||
for (i = 0; i < len; i++) {
|
for (i = 0; i < len; i++) {
|
||||||
memcpy(buf, &hex[i * 2], 2);
|
memcpy(buf, &hex[i * 2], 2);
|
||||||
|
errno = 0;
|
||||||
bytes[i] = strtoul(buf, &endp, 16);
|
bytes[i] = strtoul(buf, &endp, 16);
|
||||||
if (endp != &buf[2]) {
|
if (errno || endp != &buf[2]) {
|
||||||
free(bytes);
|
free(bytes);
|
||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
}
|
}
|
||||||
|
|
|
@ -50,11 +50,12 @@ static const char *next_s32(const char *s, int *num, int *rc)
|
||||||
if (!s || !*s)
|
if (!s || !*s)
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
*rc = -EINVAL;
|
*rc = -EINVAL;
|
||||||
*num = strtol(s, &end, 10);
|
*num = strtol(s, &end, 10);
|
||||||
if (end == NULL || s == end)
|
if (end == NULL || s == end)
|
||||||
return s;
|
return s;
|
||||||
if (*end == ' ' || *end == '\t' || *end == '\0')
|
if (errno == 0 && (*end == ' ' || *end == '\t' || *end == '\0'))
|
||||||
*rc = 0;
|
*rc = 0;
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
@ -66,11 +67,12 @@ static const char *next_u64(const char *s, uint64_t *num, int *rc)
|
||||||
if (!s || !*s)
|
if (!s || !*s)
|
||||||
return s;
|
return s;
|
||||||
|
|
||||||
|
errno = 0;
|
||||||
*rc = -EINVAL;
|
*rc = -EINVAL;
|
||||||
*num = (uint64_t) strtoumax(s, &end, 10);
|
*num = (uint64_t) strtoumax(s, &end, 10);
|
||||||
if (end == NULL || s == end)
|
if (end == NULL || s == end)
|
||||||
return s;
|
return s;
|
||||||
if (*end == ' ' || *end == '\t' || *end == '\0')
|
if (errno == 0 && (*end == ' ' || *end == '\t' || *end == '\0'))
|
||||||
*rc = 0;
|
*rc = 0;
|
||||||
return end;
|
return end;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue