restorecond: add check for strdup in strings_list_add

Check the return value of strdup() to avoid null pointer reference.

Signed-off-by: Huaxin Lu <luhuaxin1@huawei.com>
Acked-by: James Carter <jwcart2@gmail.com>
This commit is contained in:
Huaxin Lu 2023-07-11 06:49:33 +08:00 committed by James Carter
parent a7e975285c
commit 8730e0762e
1 changed files with 2 additions and 0 deletions

View File

@ -48,6 +48,8 @@ void strings_list_add(struct stringsList **list, const char *string)
if (!newptr) if (!newptr)
exitApp("Out of Memory"); exitApp("Out of Memory");
newptr->string = strdup(string); newptr->string = strdup(string);
if (!newptr->string)
exitApp("Out of Memory");
newptr->next = ptr; newptr->next = ptr;
if (prev) if (prev)
prev->next = newptr; prev->next = newptr;