Skip to content

Consideration of time of check, time of use (TOCTOU) #79

@steven-joruk

Description

@steven-joruk

Many areas of code rely on the filesystem state not being changed between checks and actions.

One example is in copy:

e.g.

  if !options.overwrite && to.as_ref().exists() {
        if options.skip_exist {
            return Ok(0);
        }

        if let Some(msg) = to.as_ref().to_str() {
            let msg = format!("Path \"{}\" exists", msg);
            err!(&msg, ErrorKind::AlreadyExists);
        }
    }

    // If the destination is created at this point then it's silently overwritten.

    Ok(std::fs::copy(from, to)?)
}

There are several examples is in copy_with_progress due to performing checks using the path rather than a descriptor.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions