fedora-selinux / selinux

Fedora SELinux Userspace
Other
21 stars 17 forks source link

libselinux: selinux_restorecon: fix realpath logic #40

Closed vmojzis closed 7 years ago

vmojzis commented 7 years ago

The realpath logic in selinux_restorecon() was taken from the Android libselinux fork. However, bionic dirname() and basename() do not modify their argument and therefore are safe to call on a const string. POSIX dirname() and basename() can modify their argument. There is a GNU basename() that does not modify its argument, but not for dirname(). For portability, create copies of the original pathname for each call and keep them around until finished using the result.

Fixes "restorecon -r goes up the tree?" bug reported by Jason Zaman.

Reported-by: Jason Zaman jason@perfinion.com Signed-off-by: Stephen Smalley sds@tycho.nsa.gov

(cherry picked from SELinuxProject commit aa0c824bb2eeb8960ba02133faade72c837ea951)

bachradsusi commented 7 years ago

It's part of upstream release 2.6