diff mbox series

restorecond: add check for strdup in strings_list_add

Message ID 20230710224933.152174-1-luhuaxin1@huawei.com (mailing list archive)
State Accepted
Commit 8730e0762e36
Delegated to: Petr Lautrbach
Headers show
Series restorecond: add check for strdup in strings_list_add | expand

Commit Message

Huaxin Lu July 10, 2023, 10:49 p.m. UTC
Check the return value of strdup() to avoid null pointer reference.

Signed-off-by: Huaxin Lu <luhuaxin1@huawei.com>
---
 restorecond/stringslist.c | 2 ++
 1 file changed, 2 insertions(+)

Comments

James Carter July 19, 2023, 6:19 p.m. UTC | #1
On Mon, Jul 10, 2023 at 9:49 PM Huaxin Lu <luhuaxin1@huawei.com> wrote:
>
> 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>


> ---
>  restorecond/stringslist.c | 2 ++
>  1 file changed, 2 insertions(+)
>
> diff --git a/restorecond/stringslist.c b/restorecond/stringslist.c
> index f9404b1..a76542a 100644
> --- a/restorecond/stringslist.c
> +++ b/restorecond/stringslist.c
> @@ -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
>
James Carter Aug. 4, 2023, 6:37 p.m. UTC | #2
On Wed, Jul 19, 2023 at 2:19 PM James Carter <jwcart2@gmail.com> wrote:
>
> On Mon, Jul 10, 2023 at 9:49 PM Huaxin Lu <luhuaxin1@huawei.com> wrote:
> >
> > 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>
>

Merged.
Thanks,
Jim

>
> > ---
> >  restorecond/stringslist.c | 2 ++
> >  1 file changed, 2 insertions(+)
> >
> > diff --git a/restorecond/stringslist.c b/restorecond/stringslist.c
> > index f9404b1..a76542a 100644
> > --- a/restorecond/stringslist.c
> > +++ b/restorecond/stringslist.c
> > @@ -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
> >
diff mbox series

Patch

diff --git a/restorecond/stringslist.c b/restorecond/stringslist.c
index f9404b1..a76542a 100644
--- a/restorecond/stringslist.c
+++ b/restorecond/stringslist.c
@@ -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;