Skip to contentSkip to conversation

libsepol/cil: Fix type confusion when writing policy.conf from CIL

PATCH In review James Carter 2 participants 3 messages Jun 4 – Jun 5 SELinux security module

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/cil: Fix type confusion when writing policy.conf from CIL

The functions __cil_cons_leaf_operand_len() and __cil_cons_leaf_operand_to_string() use the list pointer instead of the item pointer when writing out a list of names in a constraint expression.

Fix both to use the item pointer when processing a list of names.

---
 libsepol/cil/src/cil_policy.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
libsepol/cil/src/cil_policy.c +6 -7
index b56fbc81..7f20b7b7 100644
@@ -382,12 +382,11 @@ static size_t __cil_cons_leaf_operand_len(struct cil_db *db,
 	} else if (flavor == CIL_LIST) {
 		len = 1; /* "{" */
 		cil_list_for_each(i1, (struct cil_list *)operand->data) {
-			struct cil_tree_node *node = NODE(operand->data);
+			struct cil_tree_node *node = NODE(i1->data);
 			if (node->flavor == CIL_USERATTRIBUTE) {
-				len = __cil_userattribute_len(db,
-							      operand->data);
+				len = __cil_userattribute_len(db, node->data);
 			} else {
-				len += strlen(DATUM(operand->data)->fqn);
+				len += strlen(DATUM(node->data)->fqn);
 				len++; /* " " or "}" */
 			}
 		}
@@ -554,12 +553,12 @@ static char *__cil_cons_leaf_operand_to_string(struct cil_db *db,
 	} else if (flavor == CIL_LIST) {
 		*new++ = '{';
 		cil_list_for_each(i1, (struct cil_list *)operand->data) {
-			struct cil_tree_node *node = NODE(operand->data);
+			struct cil_tree_node *node = NODE(i1->data);
 			if (node->flavor == CIL_USERATTRIBUTE) {
 				new = __cil_userattribute_to_string(
-					db, operand->data, new);
+					db, node->data, new);
 			} else {
-				o_str = DATUM(operand->data)->fqn;
+				o_str = DATUM(node->data)->fqn;
 				o_len = strlen(o_str);
 				memcpy(new, o_str, o_len);
 				new += o_len;
Signature · 1 line
2.54.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 9 lines · James Carter

The functions __cil_cons_leaf_operand_len() and __cil_cons_leaf_operand_to_string() use the list pointer instead of the item pointer when writing out a list of names in a constraint expression.

Fix both to use the item pointer when processing a list of names.

Quoted 44 lines
---
 libsepol/cil/src/cil_policy.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
libsepol/cil/src/cil_policy.c +6 -8
index b56fbc81..7f20b7b7 100644
@@ -382,12 +382,11 @@ static size_t __cil_cons_leaf_operand_len(struct cil_db *db,
        } else if (flavor == CIL_LIST) {
                len = 1; /* "{" */
                cil_list_for_each(i1, (struct cil_list *)operand->data) {
-                       struct cil_tree_node *node = NODE(operand->data);
+                       struct cil_tree_node *node = NODE(i1->data);
                        if (node->flavor == CIL_USERATTRIBUTE) {
-                               len = __cil_userattribute_len(db,
-                                                             operand->data);
+                               len = __cil_userattribute_len(db, node->data);
                        } else {
-                               len += strlen(DATUM(operand->data)->fqn);
+                               len += strlen(DATUM(node->data)->fqn);
                                len++; /* " " or "}" */
                        }
                }
@@ -554,12 +553,12 @@ static char *__cil_cons_leaf_operand_to_string(struct cil_db *db,
        } else if (flavor == CIL_LIST) {
                *new++ = '{';
                cil_list_for_each(i1, (struct cil_list *)operand->data) {
-                       struct cil_tree_node *node = NODE(operand->data);
+                       struct cil_tree_node *node = NODE(i1->data);
                        if (node->flavor == CIL_USERATTRIBUTE) {
                                new = __cil_userattribute_to_string(
-                                       db, operand->data, new);
+                                       db, node->data, new);
                        } else {
-                               o_str = DATUM(operand->data)->fqn;
+                               o_str = DATUM(node->data)->fqn;
                                o_len = strlen(o_str);
                                memcpy(new, o_str, o_len);
                                new += o_len;
--

2.54.0

#2 lore raw
Quoted 8 lines · Stephen Smalley
Quoted 6 lines · James Carter

The functions __cil_cons_leaf_operand_len() and __cil_cons_leaf_operand_to_string() use the list pointer instead of the item pointer when writing out a list of names in a constraint expression.

Quoted 6 lines
Quoted 3 lines

Fix both to use the item pointer when processing a list of names.

Merged.
Jim

Quoted 44 lines
Quoted 44 lines
---
 libsepol/cil/src/cil_policy.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
libsepol/cil/src/cil_policy.c +6 -8
index b56fbc81..7f20b7b7 100644
@@ -382,12 +382,11 @@ static size_t __cil_cons_leaf_operand_len(struct cil_db *db,
        } else if (flavor == CIL_LIST) {
                len = 1; /* "{" */
                cil_list_for_each(i1, (struct cil_list *)operand->data) {
-                       struct cil_tree_node *node = NODE(operand->data);
+                       struct cil_tree_node *node = NODE(i1->data);
                        if (node->flavor == CIL_USERATTRIBUTE) {
-                               len = __cil_userattribute_len(db,
-                                                             operand->data);
+                               len = __cil_userattribute_len(db, node->data);
                        } else {
-                               len += strlen(DATUM(operand->data)->fqn);
+                               len += strlen(DATUM(node->data)->fqn);
                                len++; /* " " or "}" */
                        }
                }
@@ -554,12 +553,12 @@ static char *__cil_cons_leaf_operand_to_string(struct cil_db *db,
        } else if (flavor == CIL_LIST) {
                *new++ = '{';
                cil_list_for_each(i1, (struct cil_list *)operand->data) {
-                       struct cil_tree_node *node = NODE(operand->data);
+                       struct cil_tree_node *node = NODE(i1->data);
                        if (node->flavor == CIL_USERATTRIBUTE) {
                                new = __cil_userattribute_to_string(
-                                       db, operand->data, new);
+                                       db, node->data, new);
                        } else {
-                               o_str = DATUM(operand->data)->fqn;
+                               o_str = DATUM(node->data)->fqn;
                                o_len = strlen(o_str);
                                memcpy(new, o_str, o_len);
                                new += o_len;
--

2.54.0