Skip to content

Conversation

@abendrothj
Copy link

@abendrothj abendrothj commented Dec 23, 2025

feat: enable safe traversal on all Unix platforms

Expands the safe_traversal module support from target_os = "linux" to unix, enabling security improvements (specifically preventing TOCTOU races) on macOS and BSDs.

Changes:

  • Feature Guards: Replaced #[cfg(target_os = "linux")] with #[cfg(unix)] in uucore, du, chmod, and rm.
  • Refactoring: Renamed src/uu/rm/src/platform/linux.rs to unix.rs to reflect the broader platform support.
  • Type Safety: Added necessary type casts in safe_traversal.rs and du.rs to handle platform-specific differences in libc types (e.g., mode_t).

Verification:
Verified with cargo test on macOS.

Closes #9747

@github-actions
Copy link

GNU testsuite comparison:

Skipping an intermittent issue tests/misc/tee (passes in this run but fails in the 'main' branch)

Copy link
Contributor

@sylvestre sylvestre left a comment

Choose a reason for hiding this comment

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

plenty of jobs are failing, please fix them

- Use 'as u64' casts with clippy::unnecessary_cast suppression for
  st_nlink and st_ino to handle platform-specific type differences
- Add TOCTOU (time-of-check time-of-use) to cspell dictionary

Fixes compilation errors on FreeBSD, OpenBSD, and Android where
libc types differ from Linux/macOS (st_nlink is u16, st_ino is u32).
The cast is unnecessary on some platforms but required on others,
hence the clippy suppression.
Resolved merge conflict in src/uu/du/src/du.rs by keeping the unix
cfg guard (not target_os = "linux") to align with the PR's goal of
expanding safe_traversal to all Unix platforms.
@abendrothj abendrothj requested a review from sylvestre December 27, 2025 15:11
@sylvestre
Copy link
Contributor

Still a few job failures

@github-actions
Copy link

GNU testsuite comparison:

GNU test failed: tests/cp/cp-mv-enotsup-xattr. tests/cp/cp-mv-enotsup-xattr is passing on 'main'. Maybe you have to rebase?
Note: The gnu test tests/csplit/csplit-io-err was skipped on 'main' but is now failing.

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.

Safe traversal module only enabled on Linux

2 participants