summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJim Meyering <meyering@redhat.com>2008-01-29 08:56:48 +0100
committerJim Meyering <meyering@redhat.com>2008-01-29 09:23:51 +0100
commit533391a2a75f49da27adc71214caeeb4ef07d81c (patch)
tree9844aa22b4d1ce561e46e7b5973b7f2ed88b8309
parenta6228c5437e9f07d9f72828436b75e3358443a1c (diff)
downloadcoreutils-533391a2a75f49da27adc71214caeeb4ef07d81c.tar.xz
ls: don't segfault on files in /proc with an old libselinux
* src/ls.c (gobble_file): Work around a bug in libselinux1-2.0.15 whereby getfilecon returns 0 yet sets the context to NULL. Reported by Jan Moringen via Michael Stone in http://bugs.debian.org/463043 * tests/ls/Makefile.am (TESTS): Add proc-selinux-segfault. * tests/ls/proc-selinux-segfault: Test for the above fix. * NEWS: Mention the fix.
-rw-r--r--ChangeLog11
-rw-r--r--NEWS3
-rw-r--r--THANKS1
-rw-r--r--src/ls.c13
-rw-r--r--tests/ls/Makefile.am3
-rwxr-xr-xtests/ls/proc-selinux-segfault33
6 files changed, 62 insertions, 2 deletions
diff --git a/ChangeLog b/ChangeLog
index f89f68480..ff9070d60 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2008-01-29 Jim Meyering <meyering@redhat.com>
+
+ ls: don't segfault on files in /proc with an old libselinux
+ * src/ls.c (gobble_file): Work around a bug in libselinux1-2.0.15
+ whereby getfilecon returns 0 yet sets the context to NULL.
+ Reported by Jan Moringen via Michael Stone in
+ http://bugs.debian.org/463043
+ * tests/ls/Makefile.am (TESTS): Add proc-selinux-segfault.
+ * tests/ls/proc-selinux-segfault: Test for the above fix.
+ * NEWS: Mention the fix.
+
2008-01-26 Jim Meyering <meyering@redhat.com>
Work around Darwin9's set-GID-like group ownership inheritance.
diff --git a/NEWS b/NEWS
index 481129669..f474141a2 100644
--- a/NEWS
+++ b/NEWS
@@ -4,6 +4,9 @@ GNU coreutils NEWS -*- outline -*-
** Bug fixes
+ ls no longer segfaults on files in /proc when linked with an older version
+ of libselinux. E.g., ls -l /proc/sys would dereference a NULL pointer.
+
Fix a non-portable use of sed in configure.ac.
[bug introduced in coreutils-6.9.92]
diff --git a/THANKS b/THANKS
index f9a4f624a..1e04f9b52 100644
--- a/THANKS
+++ b/THANKS
@@ -225,6 +225,7 @@ James Youngman james+usenet@free-lunch.demon.co.uk
Jamie Lokier jamie@imbolc.ucc.ie
Jamie McClelland jm@mayfirst.org
Jan Fedak J.Fedak@sh.cvut.cz
+Jan Moringen jan.moringen@uni-bielefeld.de
Jan Nieuwenhuizen janneke@gnu.org
Janos Farkas chexum@shadow.banki.hu
Jarkko Hietaniemi jhi@epsilon.hut.fi
diff --git a/src/ls.c b/src/ls.c
index 83fac90d4..46713f26c 100644
--- a/src/ls.c
+++ b/src/ls.c
@@ -1,5 +1,5 @@
/* `dir', `vdir' and `ls' directory listing programs for GNU.
- Copyright (C) 85, 88, 90, 91, 1995-2007 Free Software Foundation, Inc.
+ Copyright (C) 85, 88, 90, 91, 1995-2008 Free Software Foundation, Inc.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
@@ -2667,6 +2667,17 @@ gobble_file (char const *name, enum filetype type, ino_t inode,
: lgetfilecon (absolute_name, &f->scontext));
err = (attr_len < 0);
+ /* Contrary to its documented API, getfilecon may return 0,
+ yet set f->scontext to NULL (on at least Debian's libselinux1
+ 2.0.15-2+b1), so work around that bug.
+ FIXME: remove this work-around in 2011, or whenever affected
+ versions of libselinux are long gone. */
+ if (attr_len == 0)
+ {
+ err = 0;
+ f->scontext = xstrdup ("unlabeled");
+ }
+
if (err == 0)
have_acl = ! STREQ ("unlabeled", f->scontext);
else
diff --git a/tests/ls/Makefile.am b/tests/ls/Makefile.am
index 2aea41951..c9739c992 100644
--- a/tests/ls/Makefile.am
+++ b/tests/ls/Makefile.am
@@ -1,6 +1,6 @@
# Make coreutils tests for "ls". -*-Makefile-*-
-# Copyright (C) 1997-2003, 2006-2007 Free Software Foundation, Inc.
+# Copyright (C) 1997-2003, 2006-2008 Free Software Foundation, Inc.
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
@@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
TESTS = \
+ proc-selinux-segfault \
stat-free-symlinks \
nameless-uid \
color-dtype-dir \
diff --git a/tests/ls/proc-selinux-segfault b/tests/ls/proc-selinux-segfault
new file mode 100755
index 000000000..320ba6f24
--- /dev/null
+++ b/tests/ls/proc-selinux-segfault
@@ -0,0 +1,33 @@
+#!/bin/sh
+# ls -l /proc/sys would segfault when built against libselinux1 2.0.15-2+b1
+
+# Copyright (C) 2008 Free Software Foundation, Inc.
+
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+if test "$VERBOSE" = yes; then
+ set -x
+ ls --version
+fi
+
+. $srcdir/../envvar-check
+. $srcdir/../test-lib.sh
+
+f=/proc/sys
+test -r $f || f=.
+
+fail=0
+ls -l $f > out || fail=1
+
+(exit $fail); exit $fail