* 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.
---
NEWS | 4 ++++
src/cp.c | 3 ++-
tests/cp/verbose-parents-quote.sh | 37 +++++++++++++++++++++++++++++++
tests/local.mk | 1 +
4 files changed, 44 insertions(+), 1 deletion(-)
create mode 100755 tests/cp/verbose-parents-quote.sh
diff --git a/NEWS b/NEWS
index f4ee8761a..bbb072cb0 100644
--- a/NEWS
+++ b/NEWS
@@ -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]
diff --git a/src/cp.c b/src/cp.c
index e17484b5d..1ba3a4fa7 100644
--- a/src/cp.c
+++ b/src/cp.c
@@ -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
diff --git a/tests/cp/verbose-parents-quote.sh
b/tests/cp/verbose-parents-quote.sh
new file mode 100755
index 000000000..0f8c034dd
--- /dev/null
+++ b/tests/cp/verbose-parents-quote.sh
@@ -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
diff --git a/tests/local.mk b/tests/local.mk
index 5794e79fc..82d7eadf3 100644
--- a/tests/local.mk
+++ b/tests/local.mk
@@ -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 \
--
2.56.0