1#!/bin/sh 2# ensure that an invalid context doesn't cause a segfault 3 4# Copyright (C) 2008-2023 Free Software Foundation, Inc. 5 6# This program is free software: you can redistribute it and/or modify 7# it under the terms of the GNU General Public License as published by 8# the Free Software Foundation, either version 3 of the License, or 9# (at your option) any later version. 10 11# This program is distributed in the hope that it will be useful, 12# but WITHOUT ANY WARRANTY; without even the implied warranty of 13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14# GNU General Public License for more details. 15 16# You should have received a copy of the GNU General Public License 17# along with this program. If not, see <https://www.gnu.org/licenses/>. 18 19. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src 20print_ver_ mkdir mkfifo mknod 21 22# Note: on an SELinux/enforcing system running mcstransd older than 23# mcstrans-0.2.8-1.fc9, the following commands may mistakenly exit 24# successfully, in spite of the invalid context string. 25require_selinux_enforcing_ 26 27c=invalid-selinux-context 28msg="failed to set default file creation context to '$c':" 29 30# Test each of mkdir, mknod, mkfifo with "-Z invalid-context". 31 32for cmd_w_arg in 'mkdir dir' 'mknod b p' 'mkfifo f'; do 33 # In OpenBSD's /bin/sh, mknod is a shell built-in. 34 # Running via "env" ensures we run our program and not the built-in. 35 env -- $cmd_w_arg --context=$c 2> out && fail=1 36 set $cmd_w_arg; cmd=$1 37 echo "$cmd: $msg" > exp || framework_failure_ 38 39 # Some systems fail with ENOTSUP, EINVAL, ENOENT, or even 40 # "Unknown system error", or "Function not implemented". 41 # For AIX 5.3: "Unsupported attribute value" 42 # For HP-UX 11.23: Unknown error (252) 43 sed \ 44 -e 's/ Not supported$//' \ 45 -e 's/ Invalid argument$//' \ 46 -e 's/ Unknown system error$//' \ 47 -e 's/ Operation not supported$//' \ 48 -e 's/ Function not implemented$//' \ 49 -e 's/ Unsupported attribute value$//' \ 50 -e 's/ Unknown error .*$//' \ 51 -e 's/ No such file or directory$//' out > k || framework_failure_ 52 mv k out || fail=1 53 compare exp out || fail=1 54done 55 56Exit $fail 57