Skip to contentSkip to conversation

restorecond: add check for strdup in strings_list_add

PATCH In review Huaxin Lu 2 participants 3 messages Jul 11, 2023 – Aug 4, 2023 SELinux security module

lore
Share & tools
lore

Huaxin Lu

author
#0 lore raw

PATCH 1/1 restorecond: add check for strdup in strings_list_add

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

---
 restorecond/stringslist.c | 2 ++
 1 file changed, 2 insertions(+)
restorecond/stringslist.c +2 -0
index f9404b1..a76542a 100644
@@ -48,6 +48,8 @@ void strings_list_add(struct stringsList **list, const char *string)
 	if (!newptr)
 		exitApp("Out of Memory");
 	newptr->string = strdup(string);
+	if (!newptr->string)
+		exitApp("Out of Memory");
 	newptr->next = ptr;
 	if (prev)
 		prev->next = newptr;
Signature · 1 line
2.33.0
Acked-by on v1 1/1
#1 lore raw
Quoted 4 lines · Huaxin Lu

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

Quoted 20 lines
---
 restorecond/stringslist.c | 2 ++
 1 file changed, 2 insertions(+)
restorecond/stringslist.c +2 -1
index f9404b1..a76542a 100644
@@ -48,6 +48,8 @@ void strings_list_add(struct stringsList **list, const char *string)
        if (!newptr)
                exitApp("Out of Memory");
        newptr->string = strdup(string);
+       if (!newptr->string)
+               exitApp("Out of Memory");
        newptr->next = ptr;
        if (prev)
                prev->next = newptr;
--

2.33.0

#2 lore raw
Quoted 9 lines · James Carter
Quoted 4 lines · Huaxin Lu

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

Merged.
Thanks,
Jim

Quoted 21 lines
Quoted 21 lines
---
 restorecond/stringslist.c | 2 ++
 1 file changed, 2 insertions(+)
restorecond/stringslist.c +2 -1
index f9404b1..a76542a 100644
@@ -48,6 +48,8 @@ void strings_list_add(struct stringsList **list, const char *string)
        if (!newptr)
                exitApp("Out of Memory");
        newptr->string = strdup(string);
+       if (!newptr->string)
+               exitApp("Out of Memory");
        newptr->next = ptr;
        if (prev)
                prev->next = newptr;
--

2.33.0