Skip to content

Commit

Permalink
Rollup merge of rust-lang#101426 - beetrees:dup-no-stdio, r=thomcc
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
JohnTitor authored Sep 5, 2022
2 parents 8f1ac8c + 0e0756c commit 4687b72
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion library/std/src/os/fd/owned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) })
}

Expand Down

0 comments on commit 4687b72

Please sign in to comment.