Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/uu/mktemp/src/mktemp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -458,12 +458,18 @@ fn dry_exec(tmpdir: &Path, prefix: &str, rand: usize, suffix: &str) -> UResult<P
fn make_temp_dir(dir: &Path, prefix: &str, rand: usize, suffix: &str) -> UResult<PathBuf> {
let mut builder = Builder::new();
builder.prefix(prefix).rand_bytes(rand).suffix(suffix);

// On *nix platforms grant read-write-execute for owner only.
// The directory is created with these permission at creation time, using mkdir(3) syscall.
// This is not relevant on Windows systems. See: https://docs.rs/tempfile/latest/tempfile/#security
// `fs` is not imported on Windows anyways.
#[cfg(not(windows))]
builder.permissions(fs::Permissions::from_mode(0o700));

match builder.tempdir_in(dir) {
Ok(d) => {
// `into_path` consumes the TempDir without removing it
let path = d.into_path();
#[cfg(not(windows))]
fs::set_permissions(&path, fs::Permissions::from_mode(0o700))?;
Ok(path)
}
Err(e) if e.kind() == ErrorKind::NotFound => {
Expand Down
Loading