From b73c78581ca55dd0e5b49351c911f713af62382f Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Tue, 16 Jan 2024 02:27:56 +0100 Subject: [PATCH] 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 --- lib/idmapping.c | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/lib/idmapping.c b/lib/idmapping.c index 5c2fe5d3..adc61af8 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; }