From: Jie Lu <lujie54@huawei.com>
To: <selinux@vger.kernel.org>
Subject: [PATCH 3/3] policycoreutils: fix potential NULL reference in load_checks
Date: Mon, 5 Dec 2022 17:36:44 +0800 [thread overview]
Message-ID: <20221205093644.703107-3-lujie54@huawei.com> (raw)
In-Reply-To: <20221205093644.703107-1-lujie54@huawei.com>
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(+)
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
next prev parent reply other threads:[~2022-12-05 12:09 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-12-05 9:36 [PATCH 1/3] libselinux: fix potential NULL reference and memory leak in audit2why Jie Lu
2022-12-05 9:36 ` [PATCH 2/3] libsepol: fix potential memory leak in common_copy_callback Jie Lu
2022-12-16 16:06 ` James Carter
2022-12-05 9:36 ` Jie Lu [this message]
2022-12-16 16:07 ` [PATCH 3/3] policycoreutils: fix potential NULL reference in load_checks James Carter
2023-01-11 15:51 ` James Carter
2022-12-16 16:03 ` [PATCH 1/3] libselinux: fix potential NULL reference and memory leak in audit2why James Carter
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20221205093644.703107-3-lujie54@huawei.com \
--to=lujie54@huawei.com \
--cc=selinux@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.