Skip to content

rm: fix path parsing for dot/dotdot protection #11005

Open
naoNao89 wants to merge 1 commit intouutils:mainfrom
naoNao89:rm-dot-protection-9749
Open

rm: fix path parsing for dot/dotdot protection #11005
naoNao89 wants to merge 1 commit intouutils:mainfrom
naoNao89:rm-dot-protection-9749

Conversation

@naoNao89
Copy link
Contributor

@naoNao89 naoNao89 commented Feb 18, 2026

Fix rm -rf ./ silently deleting contents. Improves path_is_current_or_parent_directory() to properly detect paths like ./, ../, d/., etc.

Added robust byte-level path parsing and comprehensive tests

Fixes #9749.

Future Work (maybe)

  • --preserve-root=all mount point detection
  • FTS traversal (safer directory walking)
  • Directory status caching (DS_EMPTY, DS_NONEMPTY)
    would require significant refactoring and are outside of PR

@naoNao89 naoNao89 force-pushed the rm-dot-protection-9749 branch 2 times, most recently from 27615a2 to 048da76 Compare February 18, 2026 04:32
@github-actions
Copy link

GNU testsuite comparison:

Note: The gnu test tests/pr/bounded-memory is now being skipped but was previously passing.
Congrats! The gnu test tests/cp/link-heap is now passing!

@naoNao89 naoNao89 force-pushed the rm-dot-protection-9749 branch from 048da76 to 5c3b675 Compare February 18, 2026 04:38
@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/cut/bounded-memory. tests/cut/bounded-memory is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tail/inotify-dir-recreate (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/printf/printf-surprise is now being skipped but was previously passing.
Congrats! The gnu test tests/cp/link-heap is now passing!

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)
Note: The gnu test tests/tail/pipe-f is now being skipped but was previously passing.
Congrats! The gnu test tests/cp/link-heap is now passing!

@github-actions
Copy link

GNU testsuite comparison:

Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/csplit/csplit-heap is now being skipped but was previously passing.
Note: The gnu test tests/seq/seq-epipe is now being skipped but was previously passing.
Congrats! The gnu test tests/cp/link-heap is now passing!

@naoNao89 naoNao89 force-pushed the rm-dot-protection-9749 branch from b06619a to ca8c88d Compare February 18, 2026 08:46
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/tty/tty-eof (passes in this run but fails in the 'main' branch)

@naoNao89 naoNao89 force-pushed the rm-dot-protection-9749 branch from ca8c88d to fcba02e Compare February 18, 2026 14:01
Fix path parsing in rm to properly detect and reject attempts to remove
the current directory (.) and parent directory (..), matching GNU rm behavior.

Changes:
- Rewrite path_is_current_or_parent_directory() to handle trailing slashes,
  multiple slashes, and mixed separator edge cases
- Add is_dot_or_dotdot_bytes() helper for cross-platform path component parsing
- Handle Windows backslash separators in addition to forward slashes
- Add comprehensive regression tests for edge cases:
  * Multiple trailing slashes (dir///)
  * Mixed dot and dot-dot paths (./dir/., dir/sub/..)
  * Normal files containing dots (file.txt, .hidden)
  * Mixed valid and dot arguments
  * Windows-specific edge cases with backslashes
  * Symlink resolution to dot paths

Fixes uutils#9749
@naoNao89 naoNao89 force-pushed the rm-dot-protection-9749 branch from fcba02e to 9f962fe Compare February 18, 2026 14:11
@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/pr/bounded-memory (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/cut/bounded-memory is no longer failing!
Note: The gnu test tests/unexpand/bounded-memory is now being skipped but was previously passing.

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/date/date-locale-hour. tests/date/date-locale-hour is passing on 'main'. Maybe you have to rebase?
GNU test failed: tests/rm/isatty. tests/rm/isatty is passing on 'main'. Maybe you have to rebase?
Skip an intermittent issue tests/pr/bounded-memory (fails in this run but passes in the 'main' branch)
Skip an intermittent issue tests/tty/tty-eof (fails in this run but passes in the 'main' branch)
Note: The gnu test tests/cut/bounded-memory is now being skipped but was previously passing.
Note: The gnu test tests/cut/cut-huge-range is now being skipped but was previously passing.
Congrats! The gnu test tests/seq/seq-epipe is now passing!

@codspeed-hq
Copy link

codspeed-hq bot commented Feb 18, 2026

Merging this PR will improve performance by 3.11%

⚡ 1 improved benchmark
✅ 287 untouched benchmarks
⏩ 38 skipped benchmarks1

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation du_summarize_balanced_tree[(5, 4, 10)] 7 ms 6.8 ms +3.11%

Comparing naoNao89:rm-dot-protection-9749 (9f962fe) with main (2a8eead)

Open in CodSpeed

Footnotes

  1. 38 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.

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.

rm -rf ./ and variants silently delete current directory contents

1 participant

Comments