Blame SOURCES/0011-libsepol-cil-Create-new-first-child-helper-function-.patch

212ad1
From 3e82b1e527fab1fb1dbcad8c70bdb59810a98783 Mon Sep 17 00:00:00 2001
212ad1
From: James Carter <jwcart2@gmail.com>
212ad1
Date: Tue, 30 Mar 2021 13:39:14 -0400
212ad1
Subject: [PATCH] libsepol/cil: Create new first child helper function for
212ad1
 building AST
212ad1
212ad1
In order to find statements not allowed in tunableifs, in-statements,
212ad1
macros, and booleanifs, there are tree node pointers that point to
212ad1
each of these kinds of statements when its block is being parsed.
212ad1
If the pointer is non-NULL, then the rule being parsed is in the block
212ad1
of that kind of statement.
212ad1
212ad1
The tree node pointers were being updated at the wrong point which
212ad1
prevented an invalid statement from being found if it was the first
212ad1
statement in the block of a tunableif, in-statement, macro, or
212ad1
booleanif.
212ad1
212ad1
Create a first child helper function for walking the parse tree and
212ad1
in that function set the appropriate tree node pointer if the
212ad1
current AST node is a tunableif, in-statement, macro, or booleanif.
212ad1
This also makes the code symmetrical with the last child helper
212ad1
where the tree node pointers are set to NULL.
212ad1
212ad1
Signed-off-by: James Carter <jwcart2@gmail.com>
212ad1
---
212ad1
 libsepol/cil/src/cil_build_ast.c | 42 +++++++++++++++++++-------------
212ad1
 1 file changed, 25 insertions(+), 17 deletions(-)
212ad1
212ad1
diff --git a/libsepol/cil/src/cil_build_ast.c b/libsepol/cil/src/cil_build_ast.c
212ad1
index b7245dbc..ceb55324 100644
212ad1
--- a/libsepol/cil/src/cil_build_ast.c
212ad1
+++ b/libsepol/cil/src/cil_build_ast.c
212ad1
@@ -6435,22 +6435,6 @@ int __cil_build_ast_node_helper(struct cil_tree_node *parse_current, uint32_t *f
212ad1
 
212ad1
 	if (rc == SEPOL_OK) {
212ad1
 		if (ast_current->cl_head == NULL) {
212ad1
-			if (ast_current->flavor == CIL_TUNABLEIF) {
212ad1
-				args->tunif = ast_current;
212ad1
-			}
212ad1
-
212ad1
-			if (ast_current->flavor == CIL_IN) {
212ad1
-				args->in = ast_current;
212ad1
-			}
212ad1
-
212ad1
-			if (ast_current->flavor == CIL_MACRO) {
212ad1
-				args->macro = ast_current;
212ad1
-			}
212ad1
-
212ad1
-			if (ast_current->flavor == CIL_BOOLEANIF) {
212ad1
-				args->boolif = ast_current;
212ad1
-			}
212ad1
-
212ad1
 			ast_current->cl_head = ast_node;
212ad1
 		} else {
212ad1
 			ast_current->cl_tail->next = ast_node;
212ad1
@@ -6466,6 +6450,30 @@ exit:
212ad1
 	return rc;
212ad1
 }
212ad1
 
212ad1
+int __cil_build_ast_first_child_helper(__attribute__((unused)) struct cil_tree_node *parse_current, void *extra_args)
212ad1
+{
212ad1
+	struct cil_args_build *args = extra_args;
212ad1
+	struct cil_tree_node *ast = args->ast;
212ad1
+
212ad1
+	if (ast->flavor == CIL_TUNABLEIF) {
212ad1
+		args->tunif = ast;
212ad1
+	}
212ad1
+
212ad1
+	if (ast->flavor == CIL_IN) {
212ad1
+		args->in = ast;
212ad1
+	}
212ad1
+
212ad1
+	if (ast->flavor == CIL_MACRO) {
212ad1
+		args->macro = ast;
212ad1
+	}
212ad1
+
212ad1
+	if (ast->flavor == CIL_BOOLEANIF) {
212ad1
+		args->boolif = ast;
212ad1
+	}
212ad1
+
212ad1
+	return SEPOL_OK;
212ad1
+}
212ad1
+
212ad1
 int __cil_build_ast_last_child_helper(struct cil_tree_node *parse_current, void *extra_args)
212ad1
 {
212ad1
 	struct cil_args_build *args = extra_args;
212ad1
@@ -6519,7 +6527,7 @@ int cil_build_ast(struct cil_db *db, struct cil_tree_node *parse_tree, struct ci
212ad1
 	extra_args.macro = NULL;
212ad1
 	extra_args.boolif = NULL;
212ad1
 
212ad1
-	rc = cil_tree_walk(parse_tree, __cil_build_ast_node_helper, NULL, __cil_build_ast_last_child_helper, &extra_args);
212ad1
+	rc = cil_tree_walk(parse_tree, __cil_build_ast_node_helper, __cil_build_ast_first_child_helper, __cil_build_ast_last_child_helper, &extra_args);
212ad1
 	if (rc != SEPOL_OK) {
212ad1
 		goto exit;
212ad1
 	}
212ad1
-- 
212ad1
2.30.2
212ad1