Skip to content

Commit

Permalink
Rollup merge of #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 c3faa22 + 0e0756c commit c6f6b18
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 c6f6b18

Please sign in to comment.