* NEWS: Mention the bug fix.
* src/chmod.c (main): Ensure appropriate fts config
with -P without -R.
* tests/chmod/symlinks.sh: Add a test case.

Discovered by Anthropic's OSS Scanner, as bug ANT-2026-H9P7Y138.
---
 NEWS                    | 10 ++++++++++
 src/chmod.c             |  2 ++
 tests/chmod/symlinks.sh |  5 +++++
 3 files changed, 17 insertions(+)

diff --git a/NEWS b/NEWS
index 8b1513fe4..868d96d85 100644
--- a/NEWS
+++ b/NEWS
@@ -22,6 +22,16 @@ GNU coreutils NEWS                                    -*- 
outline -*-
   when only a partial context is specified.
   [bug introduced with the chcon program in coreutils-6.9.90]
 
+  'chmod -P' without -R now correctly ignores the -P option.
+  Previously it used a symbolic link's mode, which could grant unintended
+  permissions on the target.
+  [bug introduced with the -P option in coreutils-9.5]
+
+  'chmod -h' without -R now uses the symlink's own mode to compute its
+  new permissions on systems that support changing symlink permissions.
+  Previously it used the target's mode.
+  [bug introduced with the -h option in coreutils-9.5]
+
   'chmod -R' and 'chmod -h' no longer silently skip permission changes on
   files and directories on Linux kernels before 6.6 when /proc is unavailable.
   If built on older systems with glibc < 2.39 these operations now retry
diff --git a/src/chmod.c b/src/chmod.c
index 5a7b41c2b..a182b5f82 100644
--- a/src/chmod.c
+++ b/src/chmod.c
@@ -640,6 +640,8 @@ main (int argc, char **argv)
           dereference = 0;
         }
     }
+  else
+    bit_flags = FTS_PHYSICAL | (dereference ? FTS_COMFOLLOW : 0);
 
   if (dereference == -1 && bit_flags == FTS_LOGICAL)
     dereference = 1;
diff --git a/tests/chmod/symlinks.sh b/tests/chmod/symlinks.sh
index 2578a08bb..a7c5d7d34 100755
--- a/tests/chmod/symlinks.sh
+++ b/tests/chmod/symlinks.sh
@@ -75,6 +75,11 @@ chmod 755 --no-dereference a/c/link 2>err || fail=1
 ls -l a/b > out || framework_failure_
 count_755 0
 
+# Without -R, -P applies the symbolic mode to the command-line link's target.
+chmod 640 a/b/file || framework_failure_
+chmod -P g+w a/c/link || fail=1
+test "$(stat -c %a a/b/file)" = 660 || fail=1
+
 # Dangling links should not induce an error if not dereferencing
 for noderef in '-h' '-RP' '-P'; do
   chmod 755 --no-dereference $noderef a/dangle 2>err || fail=1
-- 
2.56.0


Reply via email to