src/usermod.c: getulong_range(): Reimplement in terms of a2ul()

Reviewed-by: "Serge E. Hallyn" <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2024-01-09 17:35:29 +01:00
parent b198c1e782
commit 8ad2768472
+14 -23
View 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;
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;
}