From: Alejandro Colomar Date: Thu, 11 Jan 2024 11:17:36 +0000 (+0100) Subject: lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call X-Git-Tag: 4.17.0-rc1~119 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=7c43eb2c4ea6bbd25df2fae7539024830d03bfcf;p=thirdparty%2Fshadow.git lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call Link: Cc: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/idmapping.c b/lib/idmapping.c index da3ceefbc..3f55d8c8a 100644 --- a/lib/idmapping.c +++ b/lib/idmapping.c @@ -69,7 +69,8 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv) return NULL; } if (a2ul(&m->count, argv[argidx + 2], NULL, 0, 0, - MIN(UINT_MAX - m->lower, UINT_MAX - m->upper)) + MIN(MIN(UINT_MAX, ULONG_MAX - 1) - m->lower, + MIN(UINT_MAX, ULONG_MAX - 1) - m->upper)) == -1) { if (errno == ERANGE) { @@ -79,10 +80,6 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv) free(mappings); return NULL; } - if (ULONG_MAX - m->upper <= m->count || ULONG_MAX - m->lower <= m->count) { - fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname()); - exit(EXIT_FAILURE); - } if (m->lower + m->count < m->lower || m->upper + m->count < m->upper) { /* this one really shouldn't be possible given previous checks */ fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());