]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/gshadow.c: Use XREALLOC() instead of silently continuing on ENOMEM
authorAlejandro Colomar <alx@kernel.org>
Sun, 30 Jun 2024 21:55:56 +0000 (23:55 +0200)
committerSerge Hallyn <serge@hallyn.com>
Tue, 2 Jul 2024 02:40:11 +0000 (21:40 -0500)
We should do better, and correctly handle errors, since this is library
code.  However, I'm lazy right now, so let's die hard, and let us
improve this later.

Link: <https://github.com/shadow-maint/shadow/pull/991#discussion_r1660308154>
Reported-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/gshadow.c

index c26d8a3c5c92abc7e85c5e959615cb4e19f9c627..042138882acfcab259f1fd02731b32d68e8255a6 100644 (file)
@@ -19,6 +19,7 @@
 
 #include "alloc/malloc.h"
 #include "alloc/realloc.h"
+#include "alloc/x/xrealloc.h"
 #include "prototypes.h"
 #include "defines.h"
 
@@ -38,20 +39,14 @@ static /*@null@*/char **build_list (char *s, char **list[], size_t * nlist)
        size_t nelem = *nlist, size;
 
        while (s != NULL && *s != '\0') {
-               ptr = REALLOC(*list, nelem + 1, char *);
-               if (ptr == NULL)
-                       return NULL;
-
+               ptr = XREALLOC(*list, nelem + 1, char *);
                ptr[nelem] = strsep(&s, ",");
                nelem++;
                *list = ptr;
                *nlist = nelem;
        }
 
-       ptr = REALLOC(*list, nelem + 1, char *);
-       if (ptr == NULL)
-               return NULL;
-
+       ptr = XREALLOC(*list, nelem + 1, char *);
        ptr[nelem] = NULL;
        *list = ptr;