diff options
author | 2015-08-11 22:29:25 +0000 | |
---|---|---|
committer | 2015-08-11 22:29:25 +0000 | |
commit | 14b82553c001babb501a64d99023b602a633b8f9 (patch) | |
tree | 7002f20689295e920cc02f8fa62c2ab15149c634 /usr.bin/file/magic-common.c | |
parent | Actually leave the invalid ml in the tree after making it type NONE. (diff) | |
download | wireguard-openbsd-14b82553c001babb501a64d99023b602a633b8f9.tar.xz wireguard-openbsd-14b82553c001babb501a64d99023b602a633b8f9.zip |
Accept hexadecimal numbers without 0x if they aren't a valid decimal
number.
Diffstat (limited to 'usr.bin/file/magic-common.c')
-rw-r--r-- | usr.bin/file/magic-common.c | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/usr.bin/file/magic-common.c b/usr.bin/file/magic-common.c index c00d54f77a7..1b9f759c267 100644 --- a/usr.bin/file/magic-common.c +++ b/usr.bin/file/magic-common.c @@ -1,4 +1,4 @@ -/* $OpenBSD: magic-common.c,v 1.2 2015/08/11 21:42:16 nicm Exp $ */ +/* $OpenBSD: magic-common.c,v 1.3 2015/08/11 22:29:25 nicm Exp $ */ /* * Copyright (c) 2015 Nicholas Marriott <nicm@openbsd.org> @@ -33,12 +33,13 @@ magic_strtoull(const char *s, uint64_t *u) { char *endptr; - if (*s == '-') + if (*s == '-' || *s == '\0') return (NULL); + errno = 0; *u = strtoull(s, &endptr, 0); - if (*s == '\0') - return (NULL); + if (endptr == s) + *u = strtoull(s, &endptr, 16); if (errno == ERANGE && *u == ULLONG_MAX) return (NULL); if (*endptr == 'L') @@ -51,10 +52,13 @@ magic_strtoll(const char *s, int64_t *i) { char *endptr; - errno = 0; - *i = strtoll(s, &endptr, 0); if (*s == '\0') return (NULL); + + errno = 0; + *i = strtoll(s, &endptr, 0); + if (endptr == s) + *i = strtoll(s, &endptr, 16); if (errno == ERANGE && *i == LLONG_MAX) return (NULL); if (*endptr == 'L') |