Blame SOURCES/0025-libsepol-cil-Refactor-helper-function-for-cil_gen_no.patch

71cd55
From 63ce05ba07fc3517900fac22efe1c761d856762f Mon Sep 17 00:00:00 2001
71cd55
From: James Carter <jwcart2@gmail.com>
71cd55
Date: Thu, 8 Apr 2021 13:32:16 -0400
71cd55
Subject: [PATCH] libsepol/cil: Refactor helper function for cil_gen_node()
71cd55
71cd55
Change the name of cil_is_datum_multiple_decl() to
71cd55
cil_allow_multiple_decls() and make it static. The new function
71cd55
takes the CIL db and the flavors of the old and new datum as
71cd55
arguments. Also, put all of the logic of determining if multiple
71cd55
declarations are allowed into the new function. Finally, update
71cd55
the call from cil_gen_node().
71cd55
71cd55
Signed-off-by: James Carter <jwcart2@gmail.com>
71cd55
---
71cd55
 libsepol/cil/src/cil_build_ast.c | 27 ++++++++++-----------------
71cd55
 1 file changed, 10 insertions(+), 17 deletions(-)
71cd55
71cd55
diff --git a/libsepol/cil/src/cil_build_ast.c b/libsepol/cil/src/cil_build_ast.c
71cd55
index e57de662dbd9..14cdce1482a0 100644
71cd55
--- a/libsepol/cil/src/cil_build_ast.c
71cd55
+++ b/libsepol/cil/src/cil_build_ast.c
71cd55
@@ -82,30 +82,24 @@ exit:
71cd55
 	return rc;
71cd55
 }
71cd55
 
71cd55
-/*
71cd55
- * Determine whether or not multiple declarations of the same key can share a
71cd55
- * datum, given the new datum and the one already present in a given symtab.
71cd55
- */
71cd55
-int cil_is_datum_multiple_decl(__attribute__((unused)) struct cil_symtab_datum *cur,
71cd55
-                               struct cil_symtab_datum *old,
71cd55
-                               enum cil_flavor f)
71cd55
+static int cil_allow_multiple_decls(struct cil_db *db, enum cil_flavor f_new, enum cil_flavor f_old)
71cd55
 {
71cd55
-	int rc = CIL_FALSE;
71cd55
+	if (f_new != f_old) {
71cd55
+		return CIL_FALSE;
71cd55
+	}
71cd55
 
71cd55
-	switch (f) {
71cd55
+	switch (f_new) {
71cd55
 	case CIL_TYPE:
71cd55
 	case CIL_TYPEATTRIBUTE:
71cd55
-		if (!old || f != FLAVOR(old)) {
71cd55
-			rc = CIL_FALSE;
71cd55
-		} else {
71cd55
-			/* type and typeattribute statements insert empty datums */
71cd55
-			rc = CIL_TRUE;
71cd55
+		if (db->multiple_decls) {
71cd55
+			return CIL_TRUE;
71cd55
 		}
71cd55
 		break;
71cd55
 	default:
71cd55
 		break;
71cd55
 	}
71cd55
-	return rc;
71cd55
+
71cd55
+	return CIL_FALSE;
71cd55
 }
71cd55
 
71cd55
 int cil_gen_node(struct cil_db *db, struct cil_tree_node *ast_node, struct cil_symtab_datum *datum, hashtab_key_t key, enum cil_sym_index sflavor, enum cil_flavor nflavor)
71cd55
@@ -135,8 +129,7 @@ int cil_gen_node(struct cil_db *db, struct cil_tree_node *ast_node, struct cil_s
71cd55
 				cil_log(CIL_ERR, "Re-declaration of %s %s, but previous declaration could not be found\n",cil_node_to_string(ast_node), key);
71cd55
 				goto exit;
71cd55
 			}
71cd55
-			if (!db->multiple_decls ||
71cd55
-			    !cil_is_datum_multiple_decl(datum, prev, nflavor)) {
71cd55
+			if (!cil_allow_multiple_decls(db, nflavor, FLAVOR(prev))) {
71cd55
 				/* multiple_decls not ok, ret error */
71cd55
 				struct cil_tree_node *node = NODE(prev);
71cd55
 				cil_log(CIL_ERR, "Re-declaration of %s %s\n",
71cd55
-- 
71cd55
2.32.0
71cd55