Skip to contentSkip to conversation

libsepol/cil: avoid freeing uninitialized values

PATCH Applied Nicolas Iooss 2 participants 2 messages Mar 17, 2017 – Mar 21, 2017 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/cil: avoid freeing uninitialized values

cil_resolve_ast() begins by checking whether one of its parameters is NULL and "goto exit;" when it is the case. As extra_args has not been initialized there, this leads to calling cil_destroy_tree_node_stack(), __cil_ordered_lists_destroy()... on garbage values.

In practise this cannot happen because cil_resolve_ast() is only called by cil_compile() after cil_build_ast() succeeded. As the if condition exists nonetheless, fix the body of the if block in order to silence a warning reported by clang Static Analyzer.

---
 libsepol/cil/src/cil_resolve_ast.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_resolve_ast.c +1 -1
index 87817ca29a5f..187050116379 100644
@@ -3797,7 +3797,7 @@ int cil_resolve_ast(struct cil_db *db, struct cil_tree_node *current)
 	uint32_t changed = 0;
 
 	if (db == NULL || current == NULL) {
-		goto exit;
+		return rc;
 	}
 
 	extra_args.db = db;
Signature · 1 line
2.12.0
Applied
#1 lore raw
Quoted 11 lines · Nicolas Iooss

cil_resolve_ast() begins by checking whether one of its parameters is NULL and "goto exit;" when it is the case. As extra_args has not been initialized there, this leads to calling cil_destroy_tree_node_stack(), __cil_ordered_lists_destroy()... on garbage values.

In practise this cannot happen because cil_resolve_ast() is only called by cil_compile() after cil_build_ast() succeeded. As the if condition exists nonetheless, fix the body of the if block in order to silence a warning reported by clang Static Analyzer.

Applied.

Thanks,
Jim

Quoted 18 lines
---
 libsepol/cil/src/cil_resolve_ast.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_resolve_ast.c +1 -1
index 87817ca29a5f..187050116379 100644
@@ -3797,7 +3797,7 @@ int cil_resolve_ast(struct cil_db *db, struct cil_tree_node *current)
 	uint32_t changed = 0;
 
 	if (db == NULL || current == NULL) {
-		goto exit;
+		return rc;
 	}
 
 	extra_args.db = db;
Signature · 2 lines
James Carter <[email protected]>
National Security Agency