From: Alejandro Colomar Date: Tue, 16 Jan 2024 01:27:56 +0000 (+0100) Subject: lib/idmapping.c: get_map_ranges(): Don't exit() from a library function X-Git-Tag: 4.17.0-rc1~116 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b73c78581ca55dd0e5b49351c911f713af62382f;p=thirdparty%2Fshadow.git lib/idmapping.c: get_map_ranges(): Don't exit() from a library function Fixes: ff2baed5dbf8 ("idmapping: add more checks for overflow") Link: Reported-by: Alejandro Colomar Suggested-by: Serge Hallyn Signed-off-by: Alejandro Colomar --- diff --git a/lib/idmapping.c b/lib/idmapping.c index 5c2fe5d32..adc61af88 100644 --- a/lib/idmapping.c +++ b/lib/idmapping.c @@ -46,25 +46,21 @@ get_map_ranges(int ranges, int argc, char **argv) if (!mappings) { fprintf(log_get_logfd(), _( "%s: Memory allocation failure\n"), log_get_progname()); - exit(EXIT_FAILURE); + return NULL; } /* Gather up the ranges from the command line */ m = mappings; for (int i = 0; i < ranges * 3; i+=3, m++) { if (a2ul(&m->upper, argv[i + 0], NULL, 0, 0, UINT_MAX) == -1) { - if (errno == ERANGE) { + if (errno == ERANGE) fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname()); - exit(EXIT_FAILURE); - } free(mappings); return NULL; } if (a2ul(&m->lower, argv[i + 1], NULL, 0, 0, UINT_MAX) == -1) { - if (errno == ERANGE) { + if (errno == ERANGE) fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname()); - exit(EXIT_FAILURE); - } free(mappings); return NULL; } @@ -73,10 +69,8 @@ get_map_ranges(int ranges, int argc, char **argv) MIN(UINT_MAX, ULONG_MAX - 1) - m->upper)) == -1) { - if (errno == ERANGE) { + if (errno == ERANGE) fprintf(log_get_logfd(), _( "%s: subuid overflow detected.\n"), log_get_progname()); - exit(EXIT_FAILURE); - } free(mappings); return NULL; }