]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/gshadow.c: build_list(): Fix forever loop on ENOMEM
authorAlejandro Colomar <alx@kernel.org>
Sun, 12 May 2024 23:24:47 +0000 (01:24 +0200)
committerSerge Hallyn <serge@hallyn.com>
Tue, 2 Jul 2024 02:40:11 +0000 (21:40 -0500)
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 <alx@kernel.org>
lib/gshadow.c

index 95b9cc73b4955d2874a5966a078b8f1d4a50ecaa..407794958f9c9e54d30d8590fb500e170006337e 100644 (file)
@@ -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;
 }