diff --git a/tests/chmod/mode-whitespace.sh b/tests/chmod/mode-whitespace.sh new file mode 100755 index 000000000..2253c57c5 --- /dev/null +++ b/tests/chmod/mode-whitespace.sh @@ -0,0 +1,36 @@ +#!/bin/sh +# ensure that a mode string containing white space is rejected + +# Copyright (C) 2026 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 . + +. "${srcdir=.}/tests/init.sh"; path_prepend_ ./src +print_ver_ chmod mkdir ginstall + +touch f || framework_failure_ +chmod 600 f || framework_failure_ + +for mode in ' 644' '644 ' ' u+x' 'u+x ' 'u+x, +755' 'u+x ,g+w' 'u+x, g+w'; do + returns_ 1 chmod "$mode" f 2>/dev/null || fail=1 + returns_ 1 mkdir -m "$mode" d 2>/dev/null || fail=1 + test -d d && fail=1 + returns_ 1 ginstall -m "$mode" f g 2>/dev/null || fail=1 + test -e g && fail=1 +done + +# The mode of f must not have changed. +test "$(stat --printf=%a f)" = 600 || fail=1 + +Exit $fail diff --git a/tests/local.mk b/tests/local.mk index 7fba68215..7350316ed 100644 --- a/tests/local.mk +++ b/tests/local.mk @@ -573,6 +573,7 @@ all_tests = \ tests/chmod/equals.sh \ tests/chmod/ignore-symlink.sh \ tests/chmod/inaccessible.sh \ + tests/chmod/mode-whitespace.sh \ tests/chmod/octal.sh \ tests/chmod/only-op.sh \ tests/chmod/partial-fail.sh \