lib/idmapping.c: get_map_ranges(): Move range check to a2ul() call

Link: <https://github.com/shadow-maint/shadow/commit/ff2baed5dbf81e8967b805889f565fedb48600df#r136635300>
Cc: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
Alejandro Colomar
2024-07-11 22:42:58 -05:00
committed by Serge Hallyn
parent 5586f43d48
commit 57aa813c73
+4 -5
View File
@@ -68,7 +68,10 @@ struct map_range *get_map_ranges(int ranges, int argc, char **argv)
free(mappings);
return NULL;
}
if (a2ul(&m->count, argv[argidx + 2], NULL, 0, 0, UINT_MAX) == -1) {
if (a2ul(&m->count, argv[argidx + 2], NULL, 0, 0,
MIN(UINT_MAX - m->lower, UINT_MAX - m->upper))
== -1)
{
if (errno == ERANGE) {
fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname());
exit(EXIT_FAILURE);
@@ -80,10 +83,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->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);
}
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());