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 <module>
    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
This commit is contained in:
Jonas 5 Persson 2021-02-17 12:15:33 +01:00 committed by Snild Dolkow
parent fb9d097d03
commit aa9d421655

View file

@ -396,7 +396,8 @@ class Policy:
self.__libsepolwrap = lib self.__libsepolwrap = lib
def __GenfsDictAdd(self, Dict, buf): def __GenfsDictAdd(self, Dict, buf):
fs, path, context = buf.split(" ") fs, buf = buf.split(' ', 1)
path, context = buf.rsplit(' ', 1)
Type = context.split(":")[2] Type = context.split(":")[2]
if not fs in Dict: if not fs in Dict:
Dict[fs] = {Type} Dict[fs] = {Type}