libsepol/cil: silence static analyser's use-after-free warning
PATCH 1/1 libsepol/cil: silence static analyser's use-after-free warning
clang's static analyze reports a use-after-free in __cil_expr_to_string(), when __cil_expr_to_string_helper() does not modify its third parameter (variable s1 here) in this loop:
for (curr = curr->next; curr; curr = curr->next) {
__cil_expr_to_string_helper(curr, flavor, &s1);
cil_asprintf(&c2, "%s %s", c1, s1);
free(c1);
free(s1);
c1 = c2;
}Silence this warning by making sure s1 is always NULL at the beginning of every iteration of the loop.
--- libsepol/cil/src/cil_binary.c | 1 + 1 file changed, 1 insertion(+)
libsepol/cil/src/cil_binary.c +1 -0
@@ -2075,6 +2075,7 @@ static void __cil_expr_to_string(struct cil_list *expr, enum cil_flavor flavor,char *c2 =NULL ;__cil_expr_to_string_helper (curr, flavor, &c1);for (curr = curr->next; curr; curr = curr->next) { + s1 =NULL ;__cil_expr_to_string_helper (curr, flavor, &s1);cil_asprintf (&c2,"%s %s" , c1, s1);free (c1);
Signature · 1 line
2.20.1
Quoted 12 lines · Nicolas Iooss
clang's static analyze reports a use-after-free in
__cil_expr_to_string(), when__cil_expr_to_string_helper()does not modify its third parameter (variable s1 here) in this loop:for (curr = curr->next; curr; curr = curr->next) { __cil_expr_to_string_helper(curr, flavor, &s1); cil_asprintf(&c2, "%s %s", c1, s1); free(c1); free(s1); c1 = c2; }
Quoted 4 lines
Silence this warning by making sure s1 is always NULL at the beginning of every iteration of the loop.
Signed-off-by Nicolas Iooss <[email protected]>
Quoted 17 lines
--- libsepol/cil/src/cil_binary.c | 1 + 1 file changed, 1 insertion(+)libsepol/cil/src/cil_binary.c +1
-0@@ -2075,6 +2075,7 @@ static void __cil_expr_to_string(struct cil_list *expr, enum cil_flavor flavor,char *c2 =NULL ;__cil_expr_to_string_helper (curr, flavor, &c1);for (curr = curr->next; curr; curr = curr->next) { + s1 =NULL ;__cil_expr_to_string_helper (curr, flavor, &s1);cil_asprintf (&c2,"%s %s" , c1, s1);free (c1);
Signature · 2 lines
James Carter <[email protected]> National Security Agency
Quoted 14 lines · On Mon, Feb 11, 2019 at 8:06 PM jwcart2 <[email protected]> wrote:
Quoted 12 lines · Nicolas Iooss
clang's static analyze reports a use-after-free in
__cil_expr_to_string(), when__cil_expr_to_string_helper()does not modify its third parameter (variable s1 here) in this loop:for (curr = curr->next; curr; curr = curr->next) { __cil_expr_to_string_helper(curr, flavor, &s1); cil_asprintf(&c2, "%s %s", c1, s1); free(c1); free(s1); c1 = c2; }
Quoted 6 lines
Quoted 4 lines
Silence this warning by making sure s1 is always NULL at the beginning of every iteration of the loop.
Signed-off-by Nicolas Iooss <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Nicolas
Quoted 22 lines
Quoted 10 lines
--- libsepol/cil/src/cil_binary.c | 1 + 1 file changed, 1 insertion(+)libsepol/cil/src/cil_binary.c +0
-0libsepol/cil/src/cil_binary.c static void __cil_expr_to_string(struct cil_list *expr, enum cil_flavor flavor, · line 2081
Quoted 7 lines
libsepol/cil/src/cil_binary.c +1
-0@@ -2075,6 +2075,7 @@ static void __cil_expr_to_string(struct cil_list *expr, enum cil_flavor flavor,char *c2 =NULL ;__cil_expr_to_string_helper (curr, flavor, &c1);for (curr = curr->next; curr; curr = curr->next) { + s1 =NULL ;__cil_expr_to_string_helper (curr, flavor, &s1);cil_asprintf (&c2,"%s %s" , c1, s1);free (c1);--
James Carter <[email protected]>
National Security Agency