cp: quote directory names when --parents and --verbose are used

* src/cp.c (make_dir_parents_private): Quote the names of the directory
and the source.
* tests/cp/verbose-parents-quote.sh: New file
* tests/local.mk (all_tests): Add the new test.
* NEWS: Mention the bug.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-JJG3V3T9.
This commit is contained in:
Collin Funk committed 2026-10-25 14:32:32 -07:00
1 parent 074be5fae5
commit 7d74e197bb
4 files changed
+44 -1

No files matched your search

+4
View File
@@ -20,6 +20,10 @@ GNU coreutils NEWS -*- outline -*-
operating on dangling symbolic links.
[bug introduced in coreutils-5.3.0]
'cp --verbose --parents' now quotes the names of the parent directories that
it creates and their sources.
[This bug was present in "the beginning".]
'date -u MMDDhhmm' no longer uses the local time zone's UTC offset when
setting the date and time.
[bug introduced in coreutils-9.11]
+2 -1
View File
@@ -580,7 +580,8 @@ make_dir_parents_private (char const *const_dir, size_t src_offset,
else
{
if (verbose_fmt_string != NULL)
printf (verbose_fmt_string, src, dir);
printf (verbose_fmt_string, quoteaf_n (0, src),
quoteaf_n (1, dir));
}
/* We need search and write permissions to the new directory
+37
View File
@@ -0,0 +1,37 @@
#!/bin/sh
# Ensure that 'cp --verbose --parents' quotes messages.
# 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_ cp printf
NL='
'
mkdir -p a/b"$NL"c b &&
echo hello > a/b"$NL"c/f || framework_failure_
env printf "'a' -> 'b/a'\n"\
"%q -> %q\n"\
"%q -> %q\n" a/b"$NL"c b/a/b"$NL"c a/b"$NL"c/f b/a/b"$NL"c/f >exp-err \
|| framework_failure_
cp --parents --verbose a/b"$NL"c/f b >out >err || fail=1
compare /dev/null out || fail=1
compare exp-err err || fail=1
Exit $fail
+1
View File
@@ -615,6 +615,7 @@ all_tests = \
tests/cp/no-deref-link3.sh \
tests/cp/parent-perm.sh \
tests/cp/parent-perm-race.sh \
tests/cp/verbose-parents-quote.sh \
tests/cp/perm.sh \
tests/cp/preserve-2.sh \
tests/cp/preserve-link.sh \