All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] libselinux: add check for calloc in check_booleans
@ 2023-06-18 23:17 Huaxin Lu
  2023-06-27 14:57 ` Petr Lautrbach
  0 siblings, 1 reply; 3+ messages in thread
From: Huaxin Lu @ 2023-06-18 23:17 UTC (permalink / raw)
  To: selinux; +Cc: shenyining, fangxiuning, zhujianwei7

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

Signed-off-by: Huaxin Lu <luhuaxin1@huawei.com>
---
 libselinux/src/audit2why.c | 6 ++++++
 1 file changed, 6 insertions(+)

diff --git a/libselinux/src/audit2why.c b/libselinux/src/audit2why.c
index ba1a66e..2def89f 100644
--- a/libselinux/src/audit2why.c
+++ b/libselinux/src/audit2why.c
@@ -149,6 +149,12 @@ static int check_booleans(struct boolean_t **bools)
 
 	if (fcnt > 0) {
 		*bools = calloc(sizeof(struct boolean_t), fcnt + 1);
+		if (!*bools) {
+			PyErr_SetString( PyExc_MemoryError, "Out of memory\n");
+			free(foundlist);
+			return 0;
+		}
+	
 		struct boolean_t *b = *bools;
 		for (i = 0; i < fcnt; i++) {
 			int ctr = foundlist[i];
-- 
2.33.0


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2023-06-30 12:30 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2023-06-18 23:17 [PATCH] libselinux: add check for calloc in check_booleans Huaxin Lu
2023-06-27 14:57 ` Petr Lautrbach
2023-06-30 12:29   ` Petr Lautrbach

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.