Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Cc: Zac Medico <zmedico@g.o>
Subject: [gentoo-portage-dev] [PATCH] selinux: encode os path arguments as UTF-8 (bug 741194)
Date: Wed, 09 Sep 2020 05:30:18
Message-Id: 20200909052929.48160-1-zmedico@gentoo.org
1 Encode path arguments as UTF-8, like portage.os wrapper.
2
3 Fixes: 6137290b2bb8 ("selinux: python3 unicode paths, bug #430488")
4 Bug: https://bugs.gentoo.org/741194
5 Signed-off-by: Zac Medico <zmedico@g.o>
6 ---
7 lib/portage/_selinux.py | 16 ++++++++--------
8 1 file changed, 8 insertions(+), 8 deletions(-)
9
10 diff --git a/lib/portage/_selinux.py b/lib/portage/_selinux.py
11 index e3e18c0b8..2423ff8d6 100644
12 --- a/lib/portage/_selinux.py
13 +++ b/lib/portage/_selinux.py
14 @@ -14,7 +14,7 @@ except ImportError:
15
16 import portage
17 from portage import _encodings
18 -from portage import _native_string
19 +from portage import _native_string, _unicode_encode
20 from portage.localization import _
21
22 def copyfile(src, dest):
23 @@ -41,7 +41,6 @@ def is_selinux_enabled():
24 return selinux.is_selinux_enabled()
25
26 def mkdir(target, refdir):
27 - target = _native_string(target, encoding=_encodings['fs'], errors='strict')
28 refdir = _native_string(refdir, encoding=_encodings['fs'], errors='strict')
29 (rc, ctx) = selinux.getfilecon(refdir)
30 if rc < 0:
31 @@ -51,20 +50,21 @@ def mkdir(target, refdir):
32
33 setfscreate(ctx)
34 try:
35 - os.mkdir(target)
36 + os.mkdir(_unicode_encode(target, encoding=_encodings['fs'], errors='strict'))
37 finally:
38 setfscreate()
39
40 def rename(src, dest):
41 src = _native_string(src, encoding=_encodings['fs'], errors='strict')
42 - dest = _native_string(dest, encoding=_encodings['fs'], errors='strict')
43 (rc, ctx) = selinux.lgetfilecon(src)
44 if rc < 0:
45 raise OSError(_("rename: Failed getting context of \"%s\".") % src)
46
47 setfscreate(ctx)
48 try:
49 - os.rename(src, dest)
50 + os.rename(
51 + _unicode_encode(src, encoding=_encodings['fs'], errors='strict'),
52 + _unicode_encode(dest, encoding=_encodings['fs'], errors='strict'))
53 finally:
54 setfscreate()
55
56 @@ -132,8 +132,6 @@ class spawn_wrapper:
57 return self._spawn_func(*args, **kwargs)
58
59 def symlink(target, link, reflnk):
60 - target = _native_string(target, encoding=_encodings['fs'], errors='strict')
61 - link = _native_string(link, encoding=_encodings['fs'], errors='strict')
62 reflnk = _native_string(reflnk, encoding=_encodings['fs'], errors='strict')
63 (rc, ctx) = selinux.lgetfilecon(reflnk)
64 if rc < 0:
65 @@ -143,6 +141,8 @@ def symlink(target, link, reflnk):
66
67 setfscreate(ctx)
68 try:
69 - os.symlink(target, link)
70 + os.symlink(
71 + _unicode_encode(target, encoding=_encodings['fs'], errors='strict'),
72 + _unicode_encode(link, encoding=_encodings['fs'], errors='strict'))
73 finally:
74 setfscreate()
75 --
76 2.25.3