rust-lang / rust-lang/rust-clippy
TOCTOU: File deletion followed by file creation
Nobody has claimed this yet.
- 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 deleted and then the same file path is used to create a new file. This is a classic source of Time Of Check, Time Of Use bugs.
Advantage
The recommended code deletes and recreates an empty file in a single syscall, meaning that the act of creation acts as the check, avoiding TOCTOU bugs.
Drawbacks
No response
Example
We should detect when an argument to std::fs::remove_file is used later to create a File:
let path = "foo";
fs::remove_file(path)?;
fs::File::create(path)?;
We should detect when string literals are used too:
fs::remove_file("foo")?;
fs::File::create("foo")?;
Could be written as:
let _ = fs::OpenOptions::new()
.write(true)
.create_new(true)
.open(path)?;
Comparison with existing lints
No response
Additional Context
This is the cause for CVE 2026-35355 in uutils: https://corrode.dev/blog/bugs-rust-wont-catch/#case-study-cve-2026-35355
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.
Research direction
Start by reviewing existing rust-clippy filesystem-operation lints and the linked uutils change. Use the two Rust examples as the initial cases: a path passed to remove_file, including a string literal, then reused by File::create. Done means the lint reliably identifies that sequence and recognizes the create_new OpenOptions form as the safer alternative.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- security, tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Quiet
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100