libsepol: Fix detected RESOURCE_LEAKs
PATCH 1/1 libsepol: Fix detected RESOURCE_LEAKs
Fixes:
Error: RESOURCE_LEAK (CWE-772): [#def5]libsepol/src/kernel_to_cil.c:2380: alloc_arg: "strs_init" allocates memory that is stored into "strs". libsepol/src/kernel_to_cil.c:2386: noescape: Resource "strs" is not freed or pointed-to in "strs_add". libsepol/src/kernel_to_cil.c:2386: noescape: Resource "strs" is not freed or pointed-to in "strs_add". libsepol/src/kernel_to_cil.c:2386: noescape: Resource "strs" is not freed or pointed-to in "strs_add". libsepol/src/kernel_to_cil.c:2507: leaked_storage: Variable "strs" going out of scope leaks the storage it points to.
libsepol/src/kernel_to_conf.c:2315: alloc_arg: "strs_init" allocates memory that is stored into "strs". libsepol/src/kernel_to_conf.c:2321: noescape: Resource "strs" is not freed or pointed-to in "strs_add". libsepol/src/kernel_to_conf.c:2321: noescape: Resource "strs" is not freed or pointed-to in "strs_add". libsepol/src/kernel_to_conf.c:2321: noescape: Resource "strs" is not freed or pointed-to in "strs_add". libsepol/src/kernel_to_conf.c:2385: leaked_storage: Variable "strs" going out of scope leaks the storage it points to.
--- libsepol/src/kernel_to_cil.c | 5 +++-- libsepol/src/kernel_to_conf.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)
libsepol/src/kernel_to_cil.c +3 -2
@@ -2497,9 +2497,10 @@ static int write_user_decl_rules_to_cil(FILE *out, struct policydb *pdb)sepol_printf (out,")\n" ); } -strs_destroy (&strs); - exit: +if (strs) +strs_destroy (&strs); +if (rc !=0 ) {sepol_log_err ("Error writing user declarations to CIL\n" ); }
libsepol/src/kernel_to_conf.c +3 -2
@@ -2375,9 +2375,10 @@ static int write_user_decl_rules_to_conf(FILE *out, struct policydb *pdb)sepol_printf (out,";\n" ); } -strs_destroy (&strs); - exit: +if (strs) +strs_destroy (&strs); +if (rc !=0 ) {sepol_log_err ("Error writing user declarations to policy.conf\n" ); }
Signature · 1 line
2.32.0
Quoted 9 lines · Petr Lautrbach
Fixes:
Error:RESOURCE_LEAK(CWE-772): [#def5]libsepol/src/kernel_to_cil.c:2380:alloc_arg: "strs_init" allocates memory that is stored into "strs".libsepol/src/kernel_to_cil.c:2386: noescape: Resource "strs" is not freed or pointed-to in "strs_add".libsepol/src/kernel_to_cil.c:2386: noescape: Resource "strs" is not freed or pointed-to in "strs_add".libsepol/src/kernel_to_cil.c:2386: noescape: Resource "strs" is not freed or pointed-to in "strs_add".libsepol/src/kernel_to_cil.c:2507:leaked_storage: Variable "strs" going out of scope leaks the storage it points to.
Quoted 7 lines
libsepol/src/kernel_to_conf.c:2315:alloc_arg: "strs_init" allocates memory that is stored into "strs".libsepol/src/kernel_to_conf.c:2321: noescape: Resource "strs" is not freed or pointed-to in "strs_add".libsepol/src/kernel_to_conf.c:2321: noescape: Resource "strs" is not freed or pointed-to in "strs_add".libsepol/src/kernel_to_conf.c:2321: noescape: Resource "strs" is not freed or pointed-to in "strs_add".libsepol/src/kernel_to_conf.c:2385:leaked_storage: Variable "strs" going out of scope leaks the storage it points to.Signed-off-by Petr Lautrbach <[email protected]>
Quoted 42 lines
--- libsepol/src/kernel_to_cil.c | 5 +++-- libsepol/src/kernel_to_conf.c | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-)libsepol/src/kernel_to_cil.c +3
-2@@ -2497,9 +2497,10 @@ static int write_user_decl_rules_to_cil(FILE *out, struct policydb *pdb)sepol_printf (out,")\n" ); } -strs_destroy (&strs); - exit: +if (strs) +strs_destroy (&strs); +if (rc !=0 ) {sepol_log_err ("Error writing user declarations to CIL\n" ); }libsepol/src/kernel_to_conf.c +3
-3@@ -2375,9 +2375,10 @@ static int write_user_decl_rules_to_conf(FILE *out, struct policydb *pdb)sepol_printf (out,";\n" ); } -strs_destroy (&strs); - exit: +if (strs) +strs_destroy (&strs); +if (rc !=0 ) {sepol_log_err ("Error writing user declarations to policy.conf\n" ); } --2.32.0