about summary refs log tree commit diff
path: root/library
diff options
context:
space:
mode:
authorYuki Okushi <jtitor@2k36.org>2022-09-06 08:36:09 +0900
committerGitHub <noreply@github.com>2022-09-06 08:36:09 +0900
commitc6f6b1821d29a97b76310ab2120c416aabe2f67a (patch)
tree11afb7ed3be41d4e0f15b49104b8ee5ac2cce68c /library
parentc3faa2250c67ac040fba77828b7e042940412110 (diff)
parent0e0756cf0d1b55f3de4815088276a584e2c31f14 (diff)
downloadrust-c6f6b1821d29a97b76310ab2120c416aabe2f67a.tar.gz
rust-c6f6b1821d29a97b76310ab2120c416aabe2f67a.zip
Rollup merge of #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.
Diffstat (limited to 'library')
-rw-r--r--library/std/src/os/fd/owned.rs3
1 files changed, 2 insertions, 1 deletions
diff --git a/library/std/src/os/fd/owned.rs b/library/std/src/os/fd/owned.rs
index a463bc41db7..71e33fb9ed8 100644
--- a/library/std/src/os/fd/owned.rs
+++ b/library/std/src/os/fd/owned.rs
@@ -104,7 +104,8 @@ impl BorrowedFd<'_> {
         #[cfg(target_os = "espidf")]
         let cmd = libc::F_DUPFD;
 
-        let fd = cvt(unsafe { libc::fcntl(self.as_raw_fd(), cmd, 0) })?;
+        // Avoid using file descriptors below 3 as they are used for stdio
+        let fd = cvt(unsafe { libc::fcntl(self.as_raw_fd(), cmd, 3) })?;
         Ok(unsafe { OwnedFd::from_raw_fd(fd) })
     }