Skip to content

cp: do not write a recursive copy through a symlinked target - #14993

Open
abendrothj wants to merge 1 commit into
uutils:mainfrom
abendrothj:cp-rt-dest-symlink
Open

abendrothj wants to merge 1 commit into
uutils:mainfrom
abendrothj:cp-rt-dest-symlink

Conversation

@abendrothj

Copy link
Copy Markdown
Contributor

The top-level entry of a recursive copy was built as target.join(""), which adds a trailing separator, so the symlink check looked through a target that is a symlink. cp -rT src dst with dst a symlink to a directory copied into the link's target, and a dangling dst got the directory it points at created.

That entry now keeps the target path as given. cp -r src/. dst and dst/ still copy into what the link resolves to, as GNU does. The verbose line for the top directory loses its trailing slash, which also matches GNU, so two verbose tests are updated.

Closes #14992

Copilot AI balanced review requested due to automatic review settings October 1, 2026 01:07

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

The entry for the target itself was built as `target.join("")`, which
appends a separator, so the symlink check in copy_direntry looked through
a target that is a symlink. `cp -rT src dst` with `dst` a symlink to a
directory then copied into the link's target instead of refusing, and
`cp -r src dst` with `dst` a dangling symlink created the directory it
points at. GNU refuses both.

Keep the target path as given for that entry. `cp -r src/. dst` and a
target written with a trailing slash still copy into what the symlink
resolves to, as GNU does. The verbose line for the top directory now
reads `'src' -> 'dst'` without the slash, also matching GNU.
Copilot AI balanced review requested due to automatic review settings October 1, 2026 01:29

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@github-actions

github-actions Bot commented Oct 1, 2026

Copy link
Copy Markdown

GNU testsuite comparison:

GNU test failed: tests/id/setgid. tests/id/setgid is passing on 'main'. Maybe you have to rebase?
Skipping an intermittent issue tests/date/resolution (passes in this run but fails in the 'main' branch)

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cp: -rT copies through a target that is a symlink to a directory

2 participants