diff mbox series

libsepol: Fix markers for info nodes w/o children

Message ID 20250407023757.2183935-1-inseob@google.com (mailing list archive)
State New
Delegated to: Petr Lautrbach
Headers show
Series libsepol: Fix markers for info nodes w/o children | expand

Commit Message

Inseob Kim April 7, 2025, 2:37 a.m. UTC
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.

Signed-off-by: Inseob Kim <inseob@google.com>
---
 libsepol/cil/src/cil_write_ast.c | 4 ++++
 1 file changed, 4 insertions(+)

Comments

James Carter April 10, 2025, 6:29 p.m. UTC | #1
On Sun, Apr 6, 2025 at 10:38 PM Inseob Kim <inseob@google.com> wrote:
>
> 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.
>
> Signed-off-by: Inseob Kim <inseob@google.com>

Acked-by: James Carter <jwcart2@gmail.com>

> ---
>  libsepol/cil/src/cil_write_ast.c | 4 ++++
>  1 file changed, 4 insertions(+)
>
> diff --git a/libsepol/cil/src/cil_write_ast.c b/libsepol/cil/src/cil_write_ast.c
> index 15d8bbaf..f9edadba 100644
> --- a/libsepol/cil/src/cil_write_ast.c
> +++ b/libsepol/cil/src/cil_write_ast.c
> @@ -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
>
>
diff mbox series

Patch

diff --git a/libsepol/cil/src/cil_write_ast.c b/libsepol/cil/src/cil_write_ast.c
index 15d8bbaf..f9edadba 100644
--- a/libsepol/cil/src/cil_write_ast.c
+++ b/libsepol/cil/src/cil_write_ast.c
@@ -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;
 	}