Skip to contentSkip to conversation

libselinux: add check for calloc in check_booleans

PATCH Applied Huaxin Lu 3 participants 3 messages Jun 19, 2023 – Jun 30, 2023 SELinux security module

lore
Share & tools
lore

Huaxin Lu

author
#0 lore raw

PATCH 1/1 libselinux: add check for calloc in check_booleans

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

---
 libselinux/src/audit2why.c | 6 ++++++
 1 file changed, 6 insertions(+)
libselinux/src/audit2why.c +6 -0
index ba1a66e..2def89f 100644
@@ -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];
Signature · 1 line
2.33.0
Acked-by on v1 1/1
#1 lore raw
Quoted 12 lines · Huaxin Lu

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

---
 libselinux/src/audit2why.c | 6 ++++++
 1 file changed, 6 insertions(+)
libselinux/src/audit2why.c +0 -0
index ba1a66e..2def89f 100644

libselinux/src/audit2why.c static int check_booleans(struct boolean_t **bools) · line 157

Quoted 9 lines
libselinux/src/audit2why.c +6 -0
@@ -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;
+		}
+	

There's a trailing whitespace, but it's not necessary to resend the patch.

Quoted 5 lines
libselinux/src/audit2why.c +0 -0
 		struct boolean_t *b = *bools;
 		for (i = 0; i < fcnt; i++) {
 			int ctr = foundlist[i];
Signature · 1 line
2.33.0
#2 lore raw
Quoted 26 lines · Petr Lautrbach
Quoted 12 lines · Huaxin Lu

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

---
 libselinux/src/audit2why.c | 6 ++++++
 1 file changed, 6 insertions(+)
libselinux/src/audit2why.c +0 -0
index ba1a66e..2def89f 100644

libselinux/src/audit2why.c static int check_booleans(struct boolean_t **bools) · line 157

Quoted 9 lines
libselinux/src/audit2why.c +6 -0
@@ -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;
+		}
+	

There's a trailing whitespace, but it's not necessary to resend the patch.

Quoted 2 lines

merged, thanks

Quoted 5 lines
Quoted 5 lines
libselinux/src/audit2why.c +0 -0
 		struct boolean_t *b = *bools;
 		for (i = 0; i < fcnt; i++) {
 			int ctr = foundlist[i];
Signature · 1 line
2.33.0