diff mbox series

[3/3] policycoreutils: fix potential NULL reference in load_checks

Message ID 20221205093644.703107-3-lujie54@huawei.com (mailing list archive)
State Accepted, archived
Delegated to: James Carter
Headers show
Series [1/3] libselinux: fix potential NULL reference and memory leak in audit2why | expand

Commit Message

Jie Lu Dec. 5, 2022, 9:36 a.m. UTC
In load_checks(), add return check for malloc() to avoid NULL reference.

Signed-off-by: Jie Lu <lujie54@huawei.com>
---
 policycoreutils/sestatus/sestatus.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

James Carter Dec. 16, 2022, 4:07 p.m. UTC | #1
On Mon, Dec 5, 2022 at 7:13 AM Jie Lu <lujie54@huawei.com> wrote:
>
> In load_checks(), add return check for malloc() to avoid NULL reference.
>
> Signed-off-by: Jie Lu <lujie54@huawei.com>

Acked-by: James Carter <jwcart2@gmail.com>

> ---
>  policycoreutils/sestatus/sestatus.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/policycoreutils/sestatus/sestatus.c b/policycoreutils/sestatus/sestatus.c
> index 7dcc9944..6c95828e 100644
> --- a/policycoreutils/sestatus/sestatus.c
> +++ b/policycoreutils/sestatus/sestatus.c
> @@ -140,6 +140,8 @@ static void load_checks(char *pc[], int *npc, char *fc[], int *nfc)
>                                         pc[*npc] =
>                                             (char *)malloc((buf_len) *
>                                                            sizeof(char));
> +                                       if (!pc[*npc])
> +                                               break;
>                                         memcpy(pc[*npc], bufp, buf_len);
>                                         (*npc)++;
>                                         bufp = NULL;
> @@ -150,6 +152,8 @@ static void load_checks(char *pc[], int *npc, char *fc[], int *nfc)
>                                         fc[*nfc] =
>                                             (char *)malloc((buf_len) *
>                                                            sizeof(char));
> +                                       if (!fc[*nfc])
> +                                               break;
>                                         memcpy(fc[*nfc], bufp, buf_len);
>                                         (*nfc)++;
>                                         bufp = NULL;
> --
> 2.27.0
>
James Carter Jan. 11, 2023, 3:51 p.m. UTC | #2
On Fri, Dec 16, 2022 at 11:07 AM James Carter <jwcart2@gmail.com> wrote:
>
> On Mon, Dec 5, 2022 at 7:13 AM Jie Lu <lujie54@huawei.com> wrote:
> >
> > In load_checks(), add return check for malloc() to avoid NULL reference.
> >
> > Signed-off-by: Jie Lu <lujie54@huawei.com>
>
> Acked-by: James Carter <jwcart2@gmail.com>

This patch, but not the other two, has been merged.
Thanks,
Jim

>
> > ---
> >  policycoreutils/sestatus/sestatus.c | 4 ++++
> >  1 file changed, 4 insertions(+)
> >
> > diff --git a/policycoreutils/sestatus/sestatus.c b/policycoreutils/sestatus/sestatus.c
> > index 7dcc9944..6c95828e 100644
> > --- a/policycoreutils/sestatus/sestatus.c
> > +++ b/policycoreutils/sestatus/sestatus.c
> > @@ -140,6 +140,8 @@ static void load_checks(char *pc[], int *npc, char *fc[], int *nfc)
> >                                         pc[*npc] =
> >                                             (char *)malloc((buf_len) *
> >                                                            sizeof(char));
> > +                                       if (!pc[*npc])
> > +                                               break;
> >                                         memcpy(pc[*npc], bufp, buf_len);
> >                                         (*npc)++;
> >                                         bufp = NULL;
> > @@ -150,6 +152,8 @@ static void load_checks(char *pc[], int *npc, char *fc[], int *nfc)
> >                                         fc[*nfc] =
> >                                             (char *)malloc((buf_len) *
> >                                                            sizeof(char));
> > +                                       if (!fc[*nfc])
> > +                                               break;
> >                                         memcpy(fc[*nfc], bufp, buf_len);
> >                                         (*nfc)++;
> >                                         bufp = NULL;
> > --
> > 2.27.0
> >
diff mbox series

Patch

diff --git a/policycoreutils/sestatus/sestatus.c b/policycoreutils/sestatus/sestatus.c
index 7dcc9944..6c95828e 100644
--- a/policycoreutils/sestatus/sestatus.c
+++ b/policycoreutils/sestatus/sestatus.c
@@ -140,6 +140,8 @@  static void load_checks(char *pc[], int *npc, char *fc[], int *nfc)
 					pc[*npc] =
 					    (char *)malloc((buf_len) *
 							   sizeof(char));
+					if (!pc[*npc])
+						break;
 					memcpy(pc[*npc], bufp, buf_len);
 					(*npc)++;
 					bufp = NULL;
@@ -150,6 +152,8 @@  static void load_checks(char *pc[], int *npc, char *fc[], int *nfc)
 					fc[*nfc] =
 					    (char *)malloc((buf_len) *
 							   sizeof(char));
+					if (!fc[*nfc])
+						break;
 					memcpy(fc[*nfc], bufp, buf_len);
 					(*nfc)++;
 					bufp = NULL;