From: Alejandro Colomar Date: Thu, 11 Jan 2024 11:07:58 +0000 (+0100) Subject: lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls X-Git-Tag: 4.17.0-rc1~121 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=5586f43d48293bb61f7c42097d8bcbe50c38c643;p=thirdparty%2Fshadow.git lib/idmapping.c: get_map_ranges(): Move range check to a2ul() calls Link: Cc: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/idmapping.c b/lib/idmapping.c index 6bf7a4f93..a4a4b6811 100644 --- a/lib/idmapping.c +++ b/lib/idmapping.c @@ -15,7 +15,7 @@ #include "alloc/calloc.h" #include "alloc/x/xmalloc.h" -#include "atoi/str2i.h" +#include "atoi/a2i.h" #include "prototypes.h" #include "string/sprintf/stpeprintf.h" #include "idmapping.h" @@ -52,15 +52,27 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv) /* Gather up the ranges from the command line */ m = mappings; for (idx = 0, argidx = 0; idx < ranges; idx++, argidx += 3, m++) { - if (str2ul(&m->upper, argv[argidx + 0]) == -1) { + if (a2ul(&m->upper, argv[argidx + 0], NULL, 0, 0, UINT_MAX) == -1) { + if (errno == ERANGE) { + fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname()); + exit(EXIT_FAILURE); + } free(mappings); return NULL; } - if (str2ul(&m->lower, argv[argidx + 1]) == -1) { + if (a2ul(&m->lower, argv[argidx + 1], NULL, 0, 0, UINT_MAX) == -1) { + if (errno == ERANGE) { + fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname()); + exit(EXIT_FAILURE); + } free(mappings); return NULL; } - if (str2ul(&m->count, argv[argidx + 2]) == -1) { + if (a2ul(&m->count, argv[argidx + 2], NULL, 0, 0, UINT_MAX) == -1) { + if (errno == ERANGE) { + fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname()); + exit(EXIT_FAILURE); + } free(mappings); return NULL; } @@ -68,10 +80,6 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv) fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname()); exit(EXIT_FAILURE); } - if (m->upper > UINT_MAX || m->lower > UINT_MAX || m->count > UINT_MAX) { - fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname()); - exit(EXIT_FAILURE); - } if (m->lower + m->count > UINT_MAX || m->upper + m->count > UINT_MAX) { fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname()); exit(EXIT_FAILURE);