Skip to content

Commit

Permalink
Rollup merge of rust-lang#65316 - oconnor663:noninheritable, r=alexcr…
Browse files Browse the repository at this point in the history
…ichton

make File::try_clone produce non-inheritable handles on Windows

~**NOT READY FOR REVIEW.** This PR is currently mainly to trigger CI so that I can see what happens. (Is there a better way to trigger CI?) I don't know whether this change makes sense yet.~ (Edit: @Mark-Simulacrum clarified that CI doesn't currently run on Windows.)

---

File handles shouldn't be inheritable in general.
`std::process::Command` takes care of making them inheritable when child
processes are spawned, and the `CREATE_PROCESS_LOCK` protects against
races in that section on Windows. But `File::try_clone` has been
creating inheritable file descriptors outside of that lock, which could
be leaking into other child processes unintentionally.

See also rust-lang#31069 (comment).
  • Loading branch information
Centril committed Oct 16, 2019
2 parents 4800c24 + 93ae692 commit c2e7380
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/libstd/sys/windows/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -412,7 +412,7 @@ impl File {

pub fn duplicate(&self) -> io::Result<File> {
Ok(File {
handle: self.handle.duplicate(0, true, c::DUPLICATE_SAME_ACCESS)?,
handle: self.handle.duplicate(0, false, c::DUPLICATE_SAME_ACCESS)?,
})
}

Expand Down

0 comments on commit c2e7380

Please sign in to comment.