]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
src/usermod.c: getulong_range(): Reimplement in terms of a2ul()
authorAlejandro Colomar <alx@kernel.org>
Tue, 9 Jan 2024 16:35:29 +0000 (17:35 +0100)
committerAlejandro Colomar <alx@kernel.org>
Sat, 29 Jun 2024 18:00:18 +0000 (20:00 +0200)
Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
src/usermod.c

index f889698452a4841735f67e802c555787d61b52cb..443f7b5780579dfada2faa6c69c5266185bbe5c2 100644 (file)
@@ -33,6 +33,7 @@
 #include <time.h>
 
 #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;
 }