diff -urNp coreutils-6.10-orig/src/mkdir.c coreutils-6.10/src/mkdir.c --- coreutils-6.10-orig/src/mkdir.c 2008-03-27 14:42:40.000000000 +0100 +++ coreutils-6.10/src/mkdir.c 2008-03-27 14:51:48.000000000 +0100 @@ -211,7 +211,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)); if (options.make_ancestor_function || specified_mode) { diff -urNp coreutils-6.10-orig/src/mkfifo.c coreutils-6.10/src/mkfifo.c --- coreutils-6.10-orig/src/mkfifo.c 2008-03-29 17:53:27.000000000 +0100 +++ coreutils-6.10/src/mkfifo.c 2008-03-29 17:55:44.000000000 +0100 @@ -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 @@ -123,7 +123,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) diff -urNp coreutils-6.10-orig/src/mknod.c coreutils-6.10/src/mknod.c --- coreutils-6.10-orig/src/mknod.c 2008-03-29 17:53:27.000000000 +0100 +++ coreutils-6.10/src/mknod.c 2008-03-29 17:55:36.000000000 +0100 @@ -175,7 +175,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'. */ diff -urNp coreutils-6.10-orig/tests/mkdir/selinux coreutils-6.10/tests/mkdir/selinux --- coreutils-6.10-orig/tests/mkdir/selinux 1970-01-01 01:00:00.000000000 +0100 +++ coreutils-6.10/tests/mkdir/selinux 2008-03-29 17:58:25.000000000 +0100 @@ -0,0 +1,50 @@ +#!/bin/sh +# ensure that an invalid context doesn't cause a segfault + +# 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 . + +if test "$VERBOSE" = yes; then + set -x + mkdir --version + mkfifo --version + mknod --version +fi + +. $srcdir/../envvar-check +. $srcdir/../lang-default +. $srcdir/../test-lib.sh + +c=invalid-selinux-context +fail=0 +msg="failed to set default file creation context to \`$c':" + +# Test each of mkdir, mknod, mkfifo with "-Z invalid-context". + +for cmd_w_arg in 'mkdir dir' 'mknod b p' 'mkfifo f'; do + $cmd_w_arg -Z $c 2> out && fail=1 + set $cmd_w_arg; cmd=$1 + echo "$cmd: $msg" > exp || fail=1 + + # Some systems fail with ENOTSUP, or EINVAL, or even ENOENT. + sed \ + -e 's/ Invalid argument$//' \ + -e 's/ Operation not supported$//' \ + -e 's/ No such file or directory$//' out > k || fail=1 + mv k out || fail=1 + compare out exp || fail=1 +done + +(exit $fail); exit $fail