libsepol: cil_policy: check at least one perm exists in a classperm
PATCH 1/1 libsepol: cil_policy: check at least one perm exists in a classperm
Kernel policy language does not support an empty list of permissions, { }. CIL expressions may collapse to nothing, so ensure that we only emit a permission list if at least one permission exists.
Signed-off-by Rahul Sandhu <[email protected]>
--- libsepol/cil/src/cil_policy.c | 6 ++++++ 1 file changed, 6 insertions(+)
libsepol/cil/src/cil_policy.c +6 -0
@@ -653,6 +653,12 @@ static void cil_classperms_to_string(struct cil_classperms *classperms, struct csize_t len =0 ;char *new, *curr; +/* cil classperms are expressions, and hence may collapse to none. As an empty +list of permissions, { }, is not valid in kernel policy language, make sure +we only emit something if at least one permission exists. */ +if (cil_list_is_empty (classperms->perms)) +return ; + len +=strlen (DATUM (classperms->class)->fqn) +1 ;cil_list_for_each (i1, classperms->perms) { len +=strlen (DATUM (i1->data)->fqn) +1 ;
Signature · 1 line
2.54.0
Quoted 6 lines · Rahul Sandhu
Kernel policy language does not support an empty list of permissions, { }. CIL expressions may collapse to nothing, so ensure that we only emit a permission list if at least one permission exists.
Signed-off-by Rahul Sandhu <[email protected]>
Acked-by James Carter <[email protected]>
Quoted 24 lines
--- libsepol/cil/src/cil_policy.c | 6 ++++++ 1 file changed, 6 insertions(+)libsepol/cil/src/cil_policy.c +6
-1@@ -653,6 +653,12 @@ static void cil_classperms_to_string(struct cil_classperms *classperms, struct csize_t len =0 ;char *new, *curr; +/* cil classperms are expressions, and hence may collapse to none. As an empty +list of permissions, { }, is not valid in kernel policy language, make sure +we only emit something if at least one permission exists. */ +if (cil_list_is_empty (classperms->perms)) +return ; + len +=strlen (DATUM (classperms->class)->fqn) +1 ;cil_list_for_each (i1, classperms->perms) { len +=strlen (DATUM (i1->data)->fqn) +1 ; --2.54.0
Quoted 11 lines · James Carter
Quoted 6 lines · Rahul Sandhu
Kernel policy language does not support an empty list of permissions, { }. CIL expressions may collapse to nothing, so ensure that we only emit a permission list if at least one permission exists.
Signed-off-by Rahul Sandhu <[email protected]>Acked-by James Carter <[email protected]>
Merged.
Thanks,
Jim
Quoted 24 lines
Quoted 24 lines
--- libsepol/cil/src/cil_policy.c | 6 ++++++ 1 file changed, 6 insertions(+)libsepol/cil/src/cil_policy.c +6
-1@@ -653,6 +653,12 @@ static void cil_classperms_to_string(struct cil_classperms *classperms, struct csize_t len =0 ;char *new, *curr; +/* cil classperms are expressions, and hence may collapse to none. As an empty +list of permissions, { }, is not valid in kernel policy language, make sure +we only emit something if at least one permission exists. */ +if (cil_list_is_empty (classperms->perms)) +return ; + len +=strlen (DATUM (classperms->class)->fqn) +1 ;cil_list_for_each (i1, classperms->perms) { len +=strlen (DATUM (i1->data)->fqn) +1 ; --2.54.0