rust-lang / rust-lang/rust-clippy
TOCTOU: File creation followed by setting permissions
Open
@asder8215 is already working on this.
Since Aug 2, 2026.
A-lint
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
What it does
Detect when a file is being created and then the same file path is used to set file permissions. This is a classic source of Time Of Check, Time Of Use bugs.
Advantage
The recommended code creates the file and sets its attributes in a single syscall, avoiding TOCTOU bugs.
Drawbacks
No response
Example
// Create with default permissions
fs::create_dir(&path)?;
// Fix up permissions
fs::set_permissions(&path, Permissions::from_mode(0o700))?;
Could be written using OpenOptions::mode() and DirBuilderExt::mode().
Comparison with existing lints
No response
Additional Context
This is one of the bugs found in uutils during Canonical's audit: https://corrode.dev/blog/bugs-rust-wont-catch/#set-permissions-at-creation-time-not-after
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Assessment
This issue has not been assessed yet.