cp: reject --attributes-only self-copies (#13161) - #13894
Open
l46983284-cpu wants to merge 1 commit into
Open
Conversation
The guard added in uutils#6051 skipped handle_existing_dest for --attributes-only, losing the same-file check with it: `cp --attributes-only a a` silently succeeded. GNU rejects this with "'a' and 'a' are the same file". Add an explicit check on the attributes-only path, reusing the existing predicate so the --force --backup allowance keeps working. Signed-off-by: Alex Chen <l46983284@gmail.com>
Merging this PR will degrade performance by 4.01%
|
| Mode | Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|---|
| ❌ | Simulation | df_with_path |
573.7 µs | 704.8 µs | -18.6% |
| ⚡ | Simulation | du_max_depth_balanced_tree[(6, 4, 10)] |
65.2 ms | 62.4 ms | +4.43% |
| ⚡ | Simulation | du_summarize_balanced_tree[(5, 4, 10)] |
16.8 ms | 16.1 ms | +4.05% |
Tip
Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.
Comparing l46983284-cpu:fix-13161-cp-attronly-samefile (1c3accf) with main (822aa83)
Footnotes
-
46 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the first point of #13161.
The guard from #6051 skips handle_existing_dest for --attributes-only,
which also skipped the same-file check, so
cp --attributes-only a asilently succeeded (GNU rejects it with "'a' and 'a' are the same file").
Add an explicit check on the attributes-only path reusing
is_forbidden_to_copy_to_same_file, so the --force --backup allowance
keeps working exactly like the regular path.
Two tests cover
a aanda ./a.Note: the second point of the issue (chmod by path instead of fd, a
TOCTOU window on the normal attributes-only copy to a different file)
is intentionally left out of this PR as a follow-up.