libsepol/cil: Fix detected RESOURCE_LEAK (CWE-772)
PATCH 1/1 libsepol/cil: Fix detected RESOURCE_LEAK (CWE-772)
libsepol/cil/src/cil_binary.c:4823: alloc_arg: "bounds_check_type" allocates memory that is stored into "bad". libsepol/cil/src/cil_binary.c:4840: var_assign: Assigning: "cur" = "bad". libsepol/cil/src/cil_binary.c:4844: noescape: Resource "cur" is not freed or pointed-to in "cil_avrule_from_sepol". libsepol/cil/src/cil_binary.c:4847: leaked_storage: Variable "cur" going out of scope leaks the storage it points to. libsepol/cil/src/cil_binary.c:4847: leaked_storage: Variable "bad" going out of scope leaks the storage it points to.
--- libsepol/cil/src/cil_binary.c | 1 + 1 file changed, 1 insertion(+)
libsepol/cil/src/cil_binary.c +1 -0
@@ -4842,6 +4842,7 @@ static int cil_check_type_bounds(const struct cil_db *db, policydb_t *pdb, void rc =cil_avrule_from_sepol (pdb, cur, &target, type_value_to_cil, class_value_to_cil, perm_value_to_cil);if (rc !=SEPOL_OK ) {cil_log (CIL_ERR ,"Failed to convert sepol avrule to CIL\n" ); +bounds_destroy_bad (bad); goto exit; }__cil_print_rule (" " ,"allow" , &target);
Signature · 1 line
2.32.0
Quoted 8 lines · Petr Lautrbach
libsepol/cil/src/cil_binary.c:4823:alloc_arg: "bounds_check_type" allocates memory that is stored into "bad".libsepol/cil/src/cil_binary.c:4840:var_assign: Assigning: "cur" = "bad".libsepol/cil/src/cil_binary.c:4844: noescape: Resource "cur" is not freed or pointed-to in "cil_avrule_from_sepol".libsepol/cil/src/cil_binary.c:4847:leaked_storage: Variable "cur" going out of scope leaks the storage it points to.libsepol/cil/src/cil_binary.c:4847:leaked_storage: Variable "bad" going out of scope leaks the storage it points to.Signed-off-by Petr Lautrbach <[email protected]>
Quoted 19 lines
--- libsepol/cil/src/cil_binary.c | 1 + 1 file changed, 1 insertion(+)libsepol/cil/src/cil_binary.c +1
-1@@ -4842,6 +4842,7 @@ static int cil_check_type_bounds(const struct cil_db *db, policydb_t *pdb, void rc =cil_avrule_from_sepol (pdb, cur, &target, type_value_to_cil, class_value_to_cil, perm_value_to_cil);if (rc !=SEPOL_OK ) {cil_log (CIL_ERR ,"Failed to convert sepol avrule to CIL\n" ); +bounds_destroy_bad (bad); goto exit; }__cil_print_rule (" " ,"allow" , &target); --2.32.0
Quoted 11 lines · James Carter
Quoted 8 lines · Petr Lautrbach
libsepol/cil/src/cil_binary.c:4823:alloc_arg: "bounds_check_type" allocates memory that is stored into "bad".libsepol/cil/src/cil_binary.c:4840:var_assign: Assigning: "cur" = "bad".libsepol/cil/src/cil_binary.c:4844: noescape: Resource "cur" is not freed or pointed-to in "cil_avrule_from_sepol".libsepol/cil/src/cil_binary.c:4847:leaked_storage: Variable "cur" going out of scope leaks the storage it points to.libsepol/cil/src/cil_binary.c:4847:leaked_storage: Variable "bad" going out of scope leaks the storage it points to.Signed-off-by Petr Lautrbach <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Quoted 19 lines
Quoted 19 lines
--- libsepol/cil/src/cil_binary.c | 1 + 1 file changed, 1 insertion(+)libsepol/cil/src/cil_binary.c +1
-1@@ -4842,6 +4842,7 @@ static int cil_check_type_bounds(const struct cil_db *db, policydb_t *pdb, void rc =cil_avrule_from_sepol (pdb, cur, &target, type_value_to_cil, class_value_to_cil, perm_value_to_cil);if (rc !=SEPOL_OK ) {cil_log (CIL_ERR ,"Failed to convert sepol avrule to CIL\n" ); +bounds_destroy_bad (bad); goto exit; }__cil_print_rule (" " ,"allow" , &target); --2.32.0