Skip to content

Commit 4687b72

Browse files
authored
Rollup merge of rust-lang#101426 - beetrees:dup-no-stdio, r=thomcc
Don't duplicate file descriptors into stdio fds Ensures that file descriptors are never duplicated into the stdio fds even if a stdio fd has been closed.
2 parents 8f1ac8c + 0e0756c commit 4687b72

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Diff for: library/std/src/os/fd/owned.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,8 @@ impl BorrowedFd<'_> {
104104
#[cfg(target_os = "espidf")]
105105
let cmd = libc::F_DUPFD;
106106

107-
let fd = cvt(unsafe { libc::fcntl(self.as_raw_fd(), cmd, 0) })?;
107+
// Avoid using file descriptors below 3 as they are used for stdio
108+
let fd = cvt(unsafe { libc::fcntl(self.as_raw_fd(), cmd, 3) })?;
108109
Ok(unsafe { OwnedFd::from_raw_fd(fd) })
109110
}
110111

0 commit comments

Comments
 (0)