Skip to content

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

Merged
sylvestre merged 1 commit into
uutils:mainfrom
naoNao89:rm-dot-protection-9749
Apr 26, 2026
Merged

rm: fix path parsing for dot/dotdot protection #11005
sylvestre merged 1 commit into
uutils:mainfrom
naoNao89:rm-dot-protection-9749

Conversation

@naoNao89

@naoNao89 naoNao89 commented Feb 18, 2026

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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
Copy Markdown

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 2 times, most recently from fcba02e to 9f962fe Compare February 18, 2026 14:11
@github-actions

Copy link
Copy Markdown

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
Copy Markdown

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

codspeed-hq Bot commented Feb 18, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 309 untouched benchmarks
⏩ 46 skipped benchmarks1


Comparing naoNao89:rm-dot-protection-9749 (cb45f75) with main (0a9fc3e)2

Open in CodSpeed

Footnotes

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

  2. No successful run was found on main (07d6f27) during the generation of this report, so 0a9fc3e was used instead as the comparison base. There might be some changes unrelated to this pull request in this report.

Fixes uutils#9749: rm -rf ./ and variants silently delete current directory
contents. The path_is_current_or_parent_directory() function did not
match paths like "./" after clean_trailing_slashes() collapsed them.

Rewrite the function to strip trailing separators, extract the last
component, and check if it is "." or "..".

Co-authored-by: naoNao89 <naoNao89@users.noreply.github.com>
@sylvestre
sylvestre force-pushed the rm-dot-protection-9749 branch from 9f962fe to cb45f75 Compare April 14, 2026 21:08
@sylvestre
sylvestre merged commit 6b16cc9 into uutils:main Apr 26, 2026
168 of 169 checks passed
@naoNao89
naoNao89 deleted the rm-dot-protection-9749 branch May 6, 2026 08:49
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

2 participants