diff --git a/src/usermod.c b/src/usermod.c index f8896984..443f7b57 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; - result.first = (unsigned long)first; - result.last = (unsigned long)last; -out: + if ('-' != *pos++) + return result; + + if (a2ul(&last, pos, NULL, 10, first, UINT_MAX) == -1) + return result; + + result.first = first; + result.last = last; return result; }