summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNicolas Iooss <nicolas.iooss@m4x.org>2014-01-04 03:03:51 +0000
committerPádraig Brady <P@draigBrady.com>2014-01-13 23:11:37 +0000
commitd718331e59afb35e56445f3a1597ed74a7f3a3e2 (patch)
treee223ecfbeca136b7001a8efaacbc80e011603825 /src
parentba25b75dc2a4f37cb65b5e2ff1bf41bd1707770b (diff)
downloadcoreutils-d718331e59afb35e56445f3a1597ed74a7f3a3e2.tar.xz
copy: fix a segfault in SELinux context copying code
* src/selinux.c (restorecon_private): On ArchLinux the `fakeroot cp -a file1 file2` command segfaulted due to getfscreatecon() returning a NULL context. So map this to the sometimes ignored ENODATA error, rather than crashing. * tests/cp/no-ctx.sh: Add a new test case. * tests/local.mk: Reference the new test. * NEWS: Mention the fix. Fixes http://bugs.gnu.org/16335
Diffstat (limited to 'src')
-rw-r--r--src/selinux.c5
1 files changed, 5 insertions, 0 deletions
diff --git a/src/selinux.c b/src/selinux.c
index cd38a81e8..016db1626 100644
--- a/src/selinux.c
+++ b/src/selinux.c
@@ -192,6 +192,11 @@ restorecon_private (char const *path, bool local)
{
if (getfscreatecon (&tcon) < 0)
return rc;
+ if (!tcon)
+ {
+ errno = ENODATA;
+ return rc;
+ }
rc = lsetfilecon (path, tcon);
freecon (tcon);
return rc;