Skip to content

Commit 93ae692

Browse files
committed
make File::try_clone produce non-inheritable handles 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 #31069 (comment).
1 parent d4f7f97 commit 93ae692

File tree

1 file changed

+1
-1
lines changed
  • src/libstd/sys/windows

1 file changed

+1
-1
lines changed

src/libstd/sys/windows/fs.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,7 @@ impl File {
412412

413413
pub fn duplicate(&self) -> io::Result<File> {
414414
Ok(File {
415-
handle: self.handle.duplicate(0, true, c::DUPLICATE_SAME_ACCESS)?,
415+
handle: self.handle.duplicate(0, false, c::DUPLICATE_SAME_ACCESS)?,
416416
})
417417
}
418418

0 commit comments

Comments
 (0)