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.
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)