Skip to content

TOCTOU: opening multiple files under a directory without using open_at #17156

@estebank

Description

@estebank

What it does

Detects when file-system operations (file and directory creation, opening, deletion) are done on Paths only, opening the door to the directory the application is operating on changing from under it.

Advantage

Detecting this can help developers to eliminate a big source of TOCTOU bugs.

Drawbacks

The Dir abstraction is not yet stabilized and lacks APIs for file/directory creation and deletion. Pushing people to crates that provide these APIs might be "picking favorites".

Example

    let p = "foo";
    let bar = "bar";
    let _ = fs::File::open(p.join("bar"))?;
    let _ = fs::File::open(p.join(bar))?;

On nightly, could be written as:

    let dir = fs::Dir::open(p)?;
    let _ = dir.open("bar")?;
    let _ = dir.open(bar)?;

On stable, or for operations std doesn't have APIs for, we should mention crates like cap-std which provide open_at-like APIs.

Comparison with existing lints

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-lintArea: New lints

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions