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.
This commit is contained in:
Yuki Okushi 2022-09-06 08:36:09 +09:00 committed by GitHub
commit c6f6b1821d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) })
}