]> git.ipfire.org Git - thirdparty/coreutils.git/commitdiff
mknod, mkfifo: don't segfault when diagnosing invalid SELinux context
authorJim Meyering <meyering@redhat.com>
Fri, 28 Mar 2008 21:37:19 +0000 (22:37 +0100)
committerJim Meyering <meyering@redhat.com>
Fri, 28 Mar 2008 22:03:27 +0000 (23:03 +0100)
Identical to the bug fixed by 72d052896a9092b811961a8f3e6ca5d151a59be5.
* src/mkfifo.c (main): Use "scontext", not NULL optarg in diagnostic.
* src/mknod.c (main): Likewise.
Reported by Cristian Cadar, Daniel Dunbar and Dawson Engler.
* tests/mkdir/selinux: Test for the above fixes.
* NEWS: Mention the fixes.

NEWS
src/mkfifo.c
src/mknod.c
tests/mkdir/selinux

diff --git a/NEWS b/NEWS
index 808061c6961dc595b21e1e2f480ad6afcdfbc2de..e1349066a592157aed6c2139bc6cc1e888e0267d 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -13,6 +13,7 @@ GNU coreutils NEWS                                    -*- outline -*-
   of libselinux.  E.g., ls -l /proc/sys would dereference a NULL pointer.
 
   "mkdir -Z x dir" no longer segfaults when diagnosing invalid context "x"
+  mkfifo and mknod would fail similarly.  Now they're fixed.
 
   mv would mistakenly unlink a destination file before calling rename,
   when the destination had two or more hard links.  It no longer does that.
index 95ae21459516bfad97f0e9a1c0e9dc6f971561d6..6abd1bea9f10709f6584f6006e53346d02a48c3e 100644 (file)
@@ -1,5 +1,5 @@
 /* mkfifo -- make fifo's (named pipes)
-   Copyright (C) 90, 91, 1995-2007 Free Software Foundation, Inc.
+   Copyright (C) 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
@@ -116,7 +116,7 @@ main (int argc, char **argv)
   if (scontext && setfscreatecon (scontext) < 0)
     error (EXIT_FAILURE, errno,
           _("failed to set default file creation context to %s"),
-          quote (optarg));
+          quote (scontext));
 
   newmode = (S_IRUSR | S_IWUSR | S_IRGRP | S_IWGRP | S_IROTH | S_IWOTH);
   if (specified_mode)
index 3b85ae3fe9fefe52862466d3ab567b4b8434d25f..8a1718d6b62b5264ca667353a07cd1be51540d56 100644 (file)
@@ -1,5 +1,5 @@
 /* mknod -- make special files
-   Copyright (C) 90, 91, 1995-2007 Free Software Foundation, Inc.
+   Copyright (C) 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
@@ -168,7 +168,7 @@ main (int argc, char **argv)
   if (scontext && setfscreatecon (scontext) < 0)
     error (EXIT_FAILURE, errno,
           _("failed to set default file creation context to %s"),
-          quote (optarg));
+          quote (scontext));
 
   /* Only check the first character, to allow mnemonic usage like
      `mknod /dev/rst0 character 18 0'. */
index 9bfd0909d41521a084460612c2f695aa5ef6664d..15651ad30d58235b01e6f58b2cd7be31e6881472 100755 (executable)
@@ -19,6 +19,8 @@
 if test "$VERBOSE" = yes; then
   set -x
   mkdir --version
+  mkfifo --version
+  mknod --version
 fi
 
 . $srcdir/../envvar-check
@@ -32,7 +34,20 @@ mkdir -Z $c dir-arg 2> out && fail=1
 cat <<EOF > exp || fail=1
 mkdir: failed to set default file creation context to \`$c': Invalid argument
 EOF
+compare out exp || fail=1
+
+# Until coreutils-6.10.150, mknod and mkfifo had the same problem:
+
+mknod -Z $c b p 2> out && fail=1
+cat <<EOF > exp || fail=1
+mknod: failed to set default file creation context to \`$c': Invalid argument
+EOF
+compare out exp || fail=1
 
+mkfifo -Z $c f 2> out && fail=1
+cat <<EOF > exp || fail=1
+mkfifo: failed to set default file creation context to \`$c': Invalid argument
+EOF
 compare out exp || fail=1
 
 (exit $fail); exit $fail