Skip to contentSkip to conversation

libsepol/cil: Need to add to the length rather assigning it

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

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libsepol/cil: Need to add to the length rather assigning it

When writing a policy.conf constrain expression from a CIL policy all user attributes need to be expanded. This includes lists containing users and user attributes. When trying to determine the length of such a list the calculated length of the users in an attribute was being assigned as the length rather than added to the length.

Add to the length in this case instead of merely assigning it.

---
 libsepol/cil/src/cil_policy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_policy.c +1 -1
index 7f20b7b7..85c01050 100644
@@ -384,7 +384,7 @@ static size_t __cil_cons_leaf_operand_len(struct cil_db *db,
 		cil_list_for_each(i1, (struct cil_list *)operand->data) {
 			struct cil_tree_node *node = NODE(i1->data);
 			if (node->flavor == CIL_USERATTRIBUTE) {
-				len = __cil_userattribute_len(db, node->data);
+				len += __cil_userattribute_len(db, node->data);
 			} else {
 				len += strlen(DATUM(node->data)->fqn);
 				len++; /* " " or "}" */
Signature · 1 line
2.54.0
maintainer Acked-by on v1 1/1
#1 lore raw
Quoted 11 lines · James Carter

When writing a policy.conf constrain expression from a CIL policy all user attributes need to be expanded. This includes lists containing users and user attributes. When trying to determine the length of such a list the calculated length of the users in an attribute was being assigned as the length rather than added to the length.

Add to the length in this case instead of merely assigning it.

Quoted 21 lines
---
 libsepol/cil/src/cil_policy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_policy.c +1 -2
index 7f20b7b7..85c01050 100644
@@ -384,7 +384,7 @@ static size_t __cil_cons_leaf_operand_len(struct cil_db *db,
                cil_list_for_each(i1, (struct cil_list *)operand->data) {
                        struct cil_tree_node *node = NODE(i1->data);
                        if (node->flavor == CIL_USERATTRIBUTE) {
-                               len = __cil_userattribute_len(db, node->data);
+                               len += __cil_userattribute_len(db, node->data);
                        } else {
                                len += strlen(DATUM(node->data)->fqn);
                                len++; /* " " or "}" */
--

2.54.0

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

When writing a policy.conf constrain expression from a CIL policy all user attributes need to be expanded. This includes lists containing users and user attributes. When trying to determine the length of such a list the calculated length of the users in an attribute was being assigned as the length rather than added to the length.

Quoted 5 lines
Quoted 3 lines

Add to the length in this case instead of merely assigning it.

Merged.

Quoted 22 lines
Quoted 22 lines
---
 libsepol/cil/src/cil_policy.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
libsepol/cil/src/cil_policy.c +1 -2
index 7f20b7b7..85c01050 100644
@@ -384,7 +384,7 @@ static size_t __cil_cons_leaf_operand_len(struct cil_db *db,
                cil_list_for_each(i1, (struct cil_list *)operand->data) {
                        struct cil_tree_node *node = NODE(i1->data);
                        if (node->flavor == CIL_USERATTRIBUTE) {
-                               len = __cil_userattribute_len(db, node->data);
+                               len += __cil_userattribute_len(db, node->data);
                        } else {
                                len += strlen(DATUM(node->data)->fqn);
                                len++; /* " " or "}" */
--

2.54.0