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: 8e167d28af ("[svn-upgrade] Integrating new upstream version, shadow (4.0.8)")
Signed-off-by: Alejandro Colomar <alx@kernel.org>
This commit is contained in:
committed by
Serge Hallyn
parent
16cb664865
commit
056f1d03ee
+14
-10
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user