Skip to contentSkip to conversation

libsepol: Fix markers for info nodes w/o children

PATCH In review Inseob Kim 2 participants 3 messages Apr 7, 2025 – Apr 25, 2025 SELinux security module

lore
Share & tools
lore

Inseob Kim

author
#0 lore raw

PATCH 1/1 libsepol: Fix markers for info nodes w/o children

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 manually prints the "lme" marker in __write_cil_ast_node_helper in case there are no children, so opening markers and closing markers always match regardless of children.

---
 libsepol/cil/src/cil_write_ast.c | 4 ++++
 1 file changed, 4 insertions(+)
libsepol/cil/src/cil_write_ast.c +4 -0
index 15d8bbaf..f9edadba 100644
@@ -1624,6 +1624,10 @@ static int __write_cil_ast_node_helper(struct cil_tree_node *node, uint32_t *fin
 
 	if (node->flavor == CIL_SRC_INFO) {
 		cil_write_src_info_node(args->out, node);
+
+		if (node->cl_head == NULL) {
+			fprintf(args->out, ";;* lme\n");
+		}
 		return SEPOL_OK;
 	}
 
Signature · 1 line
2.49.0.504.g3bcea36a83-goog
Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · Inseob Kim

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 manually prints the "lme" marker in __write_cil_ast_node_helper in case there are no children, so opening markers and closing markers always match regardless of children.

Quoted 23 lines
---
 libsepol/cil/src/cil_write_ast.c | 4 ++++
 1 file changed, 4 insertions(+)
libsepol/cil/src/cil_write_ast.c +4 -1
index 15d8bbaf..f9edadba 100644
@@ -1624,6 +1624,10 @@ static int __write_cil_ast_node_helper(struct cil_tree_node *node, uint32_t *fin
 
        if (node->flavor == CIL_SRC_INFO) {
                cil_write_src_info_node(args->out, node);
+
+               if (node->cl_head == NULL) {
+                       fprintf(args->out, ";;* lme\n");
+               }
                return SEPOL_OK;
        }
 
--

2.49.0.504.g3bcea36a83-goog

#2 lore raw
Quoted 8 lines · James Carter
Quoted 6 lines · Inseob Kim

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.

Quoted 8 lines
Quoted 5 lines

This change manually prints the "lme" marker in __write_cil_ast_node_helper in case there are no children, so opening markers and closing markers always match regardless of children.

Merged.
Thanks,
Jim

Quoted 23 lines
Quoted 23 lines
---
 libsepol/cil/src/cil_write_ast.c | 4 ++++
 1 file changed, 4 insertions(+)
libsepol/cil/src/cil_write_ast.c +4 -1
index 15d8bbaf..f9edadba 100644
@@ -1624,6 +1624,10 @@ static int __write_cil_ast_node_helper(struct cil_tree_node *node, uint32_t *fin
 
        if (node->flavor == CIL_SRC_INFO) {
                cil_write_src_info_node(args->out, node);
+
+               if (node->cl_head == NULL) {
+                       fprintf(args->out, ";;* lme\n");
+               }
                return SEPOL_OK;
        }
 
--

2.49.0.504.g3bcea36a83-goog