From: Alejandro Colomar Date: Tue, 9 Jan 2024 16:35:29 +0000 (+0100) Subject: src/usermod.c: getulong_range(): Reimplement in terms of a2ul() X-Git-Tag: 4.17.0-rc1~212 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ad276847229acec78cc147966179dee90da9d9d;p=thirdparty%2Fshadow.git src/usermod.c: getulong_range(): Reimplement in terms of a2ul() Reviewed-by: "Serge E. Hallyn" Signed-off-by: Alejandro Colomar --- diff --git a/src/usermod.c b/src/usermod.c index f88969845..443f7b578 100644 --- a/src/usermod.c +++ b/src/usermod.c @@ -33,6 +33,7 @@ #include #include "alloc.h" +#include "atoi/a2i.h" #include "atoi/str2i.h" #include "chkname.h" #include "defines.h" @@ -302,35 +303,25 @@ struct ulong_range static struct ulong_range getulong_range(const char *str) { - struct ulong_range result = { .first = ULONG_MAX, .last = 0 }; - long long first, last; - char *pos; - - errno = 0; - first = strtoll(str, &pos, 10); - if (('\0' == *str) || ('-' != *pos ) || (0 != errno) || - (first != (unsigned long)first)) - goto out; - - errno = 0; - last = strtoll(pos + 1, &pos, 10); - if (('\0' != *pos ) || (0 != errno) || - (last != (unsigned long)last)) - goto out; - - if (first > last) - goto out; + char *pos; + unsigned long first, last; + struct ulong_range result = { .first = ULONG_MAX, .last = 0 }; /* * uid_t in linux is an unsigned int, anything over this is an invalid * range will be later refused anyway by get_map_ranges(). */ - if (first > UINT_MAX || last > UINT_MAX) - goto out; + if (a2ul(&first, str, &pos, 10, 0, UINT_MAX) == -1 && errno != ENOTSUP) + return result; + + if ('-' != *pos++) + return result; + + if (a2ul(&last, pos, NULL, 10, first, UINT_MAX) == -1) + return result; - result.first = (unsigned long)first; - result.last = (unsigned long)last; -out: + result.first = first; + result.last = last; return result; }