Skip to contentSkip to conversation

libsepol: Print info nodes at the first child

PATCH Superseded Inseob Kim 1 participant 1 message Mar 17, 2025 SELinux security module

lore
Share & tools
lore

Inseob Kim

author
#0 lore raw

PATCH 1/1 libsepol: Print info nodes at the first child

cil_write_src_info_node has been called with __write_cil_ast_node_helper, but that may break the result CIL file in case there are no children for the info node, because the "lme" marker is printed with __write_cil_ast_last_child_helper.

This change moves the cil_write_src_info_node call to __write_cil_ast_first_child_helper, so opening markers and closing markers always match.

---
 libsepol/cil/src/cil_write_ast.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
libsepol/cil/src/cil_write_ast.c +4 -1
index 15d8bbaf..7f41387f 100644
@@ -1623,7 +1623,6 @@ static int __write_cil_ast_node_helper(struct cil_tree_node *node, uint32_t *fin
 	struct cil_write_ast_args *args = extra_args;
 
 	if (node->flavor == CIL_SRC_INFO) {
-		cil_write_src_info_node(args->out, node);
 		return SEPOL_OK;
 	}
 
@@ -1643,6 +1642,10 @@ static int __write_cil_ast_first_child_helper(struct cil_tree_node *node, void *
 	struct cil_write_ast_args *args = extra_args;
 	struct cil_tree_node *parent = node->parent;
 
+	if (parent->flavor == CIL_SRC_INFO) {
+		cil_write_src_info_node(args->out, parent);
+	}
+
 	if (parent->flavor != CIL_SRC_INFO && parent->flavor != CIL_ROOT) {
 		args->depth++;
 	}
Signature · 1 line
2.49.0.rc1.451.g8f38331e32-goog