tests: chmod: ensure modes containing white space are rejected

* tests/chmod/mode-whitespace.sh: New test.  Check that chmod,
mkdir -m and install -m reject mode strings with leading or trailing
white space, or white space around a ',' separator.
* tests/local.mk (all_tests): Reference the new test.
https://github.com/uutils/coreutils/pull/16193

Link: https://github.com/coreutils/coreutils/pull/447
This commit is contained in:
Sylvestre Ledru authored and Pádraig Brady committed 2026-11-08 14:06:17 +00:00
1 parent 27e21ce402
commit e0c24f5866
2 files changed
+37

No files matched your search

+36
View File
@@ -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 <https://www.gnu.org/licenses/>.
. "${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
+1
View File
@@ -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 \