Skip to contentSkip to conversation

checkpolicy: use calloc() so no need to do memset()

PATCH In review Kalevi Kolttonen 2 participants 3 messages May 13 – May 20 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 checkpolicy: use calloc() so no need to do memset()

---
 checkpolicy/checkpolicy.c     | 4 +---
 checkpolicy/module_compiler.c | 3 +--
 2 files changed, 2 insertions(+), 5 deletions(-)
checkpolicy/checkpolicy.c +1 -3
index b808e4d0..323e11ca 100644
@@ -235,13 +235,11 @@ static int identify_equiv_types(void)
 	 * Create a list of access vector rules for each type
 	 * from the access vector table.
 	 */
-	type_rules = malloc(sizeof(struct avtab_node) * policydb.p_types.nprim);
+	type_rules = calloc(policydb.p_types.nprim, sizeof(struct avtab_node));
 	if (!type_rules) {
 		fprintf(stderr, "out of memory\n");
 		exit(1);
 	}
-	memset(type_rules, 0,
-	       sizeof(struct avtab_node) * policydb.p_types.nprim);
 	if (avtab_map(&policydb.te_avtab, create_type_rules, type_rules))
 		exit(1);
 
checkpolicy/module_compiler.c +1 -2
index 4b2f98d8..a6ecc939 100644
@@ -842,12 +842,11 @@ int require_class(int pass)
 				return -1;
 			}
 			allocated = 1;
-			if ((perm = malloc(sizeof(*perm))) == NULL) {
+			if ((perm = calloc(1, sizeof(*perm))) == NULL) {
 				yyerror("Out of memory!");
 				free(perm_id);
 				return -1;
 			}
-			memset(perm, 0, sizeof(*perm));
 			ret =
 			    hashtab_insert(datum->permissions.table, perm_id,
 					   perm);
Signature · 1 line
2.54.0
Acked-by on v3 1/1
#1 lore raw
Quoted 2 lines · Kalevi Kolttonen
Quoted 46 lines
---
 checkpolicy/checkpolicy.c     | 4 +---
 checkpolicy/module_compiler.c | 3 +--
 2 files changed, 2 insertions(+), 5 deletions(-)
checkpolicy/checkpolicy.c +1 -3
index b808e4d0..323e11ca 100644
@@ -235,13 +235,11 @@ static int identify_equiv_types(void)
         * Create a list of access vector rules for each type
         * from the access vector table.
         */
-       type_rules = malloc(sizeof(struct avtab_node) * policydb.p_types.nprim);
+       type_rules = calloc(policydb.p_types.nprim, sizeof(struct avtab_node));
        if (!type_rules) {
                fprintf(stderr, "out of memory\n");
                exit(1);
        }
-       memset(type_rules, 0,
-              sizeof(struct avtab_node) * policydb.p_types.nprim);
        if (avtab_map(&policydb.te_avtab, create_type_rules, type_rules))
                exit(1);
 
checkpolicy/module_compiler.c +1 -3
index 4b2f98d8..a6ecc939 100644
@@ -842,12 +842,11 @@ int require_class(int pass)
                                return -1;
                        }
                        allocated = 1;
-                       if ((perm = malloc(sizeof(*perm))) == NULL) {
+                       if ((perm = calloc(1, sizeof(*perm))) == NULL) {
                                yyerror("Out of memory!");
                                free(perm_id);
                                return -1;
                        }
-                       memset(perm, 0, sizeof(*perm));
                        ret =
                            hashtab_insert(datum->permissions.table, perm_id,
                                           perm);
--

2.54.0

#2 lore raw
Quoted 7 lines · James Carter
Quoted 2 lines · Kalevi Kolttonen

Merged.
Thanks,
Jim

Quoted 46 lines
Quoted 46 lines
---
 checkpolicy/checkpolicy.c     | 4 +---
 checkpolicy/module_compiler.c | 3 +--
 2 files changed, 2 insertions(+), 5 deletions(-)
checkpolicy/checkpolicy.c +1 -3
index b808e4d0..323e11ca 100644
@@ -235,13 +235,11 @@ static int identify_equiv_types(void)
         * Create a list of access vector rules for each type
         * from the access vector table.
         */
-       type_rules = malloc(sizeof(struct avtab_node) * policydb.p_types.nprim);
+       type_rules = calloc(policydb.p_types.nprim, sizeof(struct avtab_node));
        if (!type_rules) {
                fprintf(stderr, "out of memory\n");
                exit(1);
        }
-       memset(type_rules, 0,
-              sizeof(struct avtab_node) * policydb.p_types.nprim);
        if (avtab_map(&policydb.te_avtab, create_type_rules, type_rules))
                exit(1);
 
checkpolicy/module_compiler.c +1 -3
index 4b2f98d8..a6ecc939 100644
@@ -842,12 +842,11 @@ int require_class(int pass)
                                return -1;
                        }
                        allocated = 1;
-                       if ((perm = malloc(sizeof(*perm))) == NULL) {
+                       if ((perm = calloc(1, sizeof(*perm))) == NULL) {
                                yyerror("Out of memory!");
                                free(perm_id);
                                return -1;
                        }
-                       memset(perm, 0, sizeof(*perm));
                        ret =
                            hashtab_insert(datum->permissions.table, perm_id,
                                           perm);
--

2.54.0