From e0c24f5866217bc9aebb883af77250fd5f8aacba Mon Sep 17 00:00:00 2001 From: Sylvestre Ledru Date: Sun, 8 Nov 2026 12:14:06 +0100 Subject: [PATCH] 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 --- tests/chmod/mode-whitespace.sh | 36 ++++++++++++++++++++++++++++++++++ tests/local.mk | 1 + 2 files changed, 37 insertions(+) create mode 100755 tests/chmod/mode-whitespace.sh 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 \