From aa9d421655c3cfbb95f3fbeba327b6685e68cb23 Mon Sep 17 00:00:00 2001 From: Jonas 5 Persson Date: Wed, 17 Feb 2021 12:15:33 +0100 Subject: [PATCH] Allow policy tests to support space in file names Though libsepol supports it since selinux commit 644c5bbb, test code couldn't handle whitespace in file name in policy database. Solved by splitting string once from left and then once from right to avoid split of whitespace in file name. Minimal reproducing example: $ echo '(genfscon sysfs "/s/p a/ce" (USER ROLE TYPE ((SENS) (SENS))))' > s.cil $ secilc -m -o s.db external/selinux/secilc/test/minimum.cil s.cil $ searchpolicy --libpath out/host/linux-x86/lib64/libsepolwrap.so -sX --allow s.db Traceback (most recent call last): File "/tmp/Soong.python_ra9it1nk/searchpolicy.py", line 52, in pol = policy.Policy(args.policy, None, args.libpath) File "/tmp/Soong.python_ra9it1nk/policy.py", line 460, in __init__ self.__InitGenfsCon() File "/tmp/Soong.python_ra9it1nk/policy.py", line 419, in __InitGenfsCon self.__GenfsDictAdd(self.__GenfsDict, buf.value.decode("ascii")) File "/tmp/Soong.python_ra9it1nk/policy.py", line 399, in __GenfsDictAdd fs, path, context = buf.split(" ") ValueError: too many values to unpack (expected 3) Test: manual, as described above Test: cts SELinuxHostTest with spaces in a genfscon path Change-Id: I7c74292513a63819ee7dc03ab4977ce9363589a4 --- tests/policy.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/policy.py b/tests/policy.py index 06157fd16..60c696294 100644 --- a/tests/policy.py +++ b/tests/policy.py @@ -396,7 +396,8 @@ class Policy: self.__libsepolwrap = lib def __GenfsDictAdd(self, Dict, buf): - fs, path, context = buf.split(" ") + fs, buf = buf.split(' ', 1) + path, context = buf.rsplit(' ', 1) Type = context.split(":")[2] if not fs in Dict: Dict[fs] = {Type}