Skip to contentSkip to conversation

libselinux: Fix ordering of arguments to calloc

PATCH In review James Carter 1 participant 2 messages Jan 5, 2024 – Jan 25, 2024 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libselinux: Fix ordering of arguments to calloc

The number of elements should be first and the size of the elements second.

---
 libselinux/src/audit2why.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libselinux/src/audit2why.c +2 -2
index 8c4c07d5..ad846cc3 100644
@@ -148,7 +148,7 @@ static int check_booleans(struct boolean_t **bools)
 		sepol_bool_free(boolean);
 
 	if (fcnt > 0) {
-		*bools = calloc(sizeof(struct boolean_t), fcnt + 1);
+		*bools = calloc(fcnt + 1, sizeof(struct boolean_t));
 		if (!*bools) {
 			PyErr_SetString( PyExc_MemoryError, "Out of memory\n");
 			free(foundlist);
@@ -226,7 +226,7 @@ static int __policy_init(const char *init_path)
 		return 1;
 	}
 
-	avc = calloc(sizeof(struct avc_t), 1);
+	avc = calloc(1, sizeof(struct avc_t));
 	if (!avc) {
 		PyErr_SetString( PyExc_MemoryError, "Out of memory\n");
 		fclose(fp);
Signature · 1 line
2.43.0
#1 lore raw
Quoted 5 lines · James Carter

The number of elements should be first and the size of the elements second.

This patch has been merged.
Jim

Quoted 29 lines
---
 libselinux/src/audit2why.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
libselinux/src/audit2why.c +2 -3
index 8c4c07d5..ad846cc3 100644
@@ -148,7 +148,7 @@ static int check_booleans(struct boolean_t **bools)
                sepol_bool_free(boolean);
 
        if (fcnt > 0) {
-               *bools = calloc(sizeof(struct boolean_t), fcnt + 1);
+               *bools = calloc(fcnt + 1, sizeof(struct boolean_t));
                if (!*bools) {
                        PyErr_SetString( PyExc_MemoryError, "Out of memory\n");
                        free(foundlist);
@@ -226,7 +226,7 @@ static int __policy_init(const char *init_path)
                return 1;
        }
 
-       avc = calloc(sizeof(struct avc_t), 1);
+       avc = calloc(1, sizeof(struct avc_t));
        if (!avc) {
                PyErr_SetString( PyExc_MemoryError, "Out of memory\n");
                fclose(fp);
--

2.43.0