From 056f1d03ee93b47ad7b2338430580c7edf3e5108 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 13 May 2024 01:24:47 +0200 Subject: [PATCH] lib/gshadow.c: build_list(): Fix forever loop on ENOMEM Before this patch, the function looped while (s != NULL && *s != '\0'). However, nothing was modifying that string if REALLOC() failed, so the loop was forever. Fixes: 8e167d28afd6 ("[svn-upgrade] Integrating new upstream version, shadow (4.0.8)") Signed-off-by: Alejandro Colomar --- lib/gshadow.c | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/gshadow.c b/lib/gshadow.c index 95b9cc73b..407794958 100644 --- a/lib/gshadow.c +++ b/lib/gshadow.c @@ -39,19 +39,23 @@ static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist) while (s != NULL && *s != '\0') { size = (nelem + 1) * sizeof (ptr); ptr = REALLOC(*list, size, char *); - if (NULL != ptr) { - ptr[nelem] = strsep(&s, ","); - nelem++; - *list = ptr; - *nlist = nelem; - } + if (ptr == NULL) + return NULL; + + ptr[nelem] = strsep(&s, ","); + nelem++; + *list = ptr; + *nlist = nelem; } + size = (nelem + 1) * sizeof (ptr); ptr = REALLOC(*list, size, char *); - if (NULL != ptr) { - ptr[nelem] = NULL; - *list = ptr; - } + if (ptr == NULL) + return NULL; + + ptr[nelem] = NULL; + *list = ptr; + return ptr; } -- 2.47.3