Visitar URL original
Return EBADF for negative stat file descriptors by youknowdot · Pull Request #9008 · RustPython/RustPython · GitHub
Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Reject negative file descriptors before fstat
Return EBADF for negative ordinary descriptors before calling rustix, avoiding debug-build assertions on canonical invalid-fd tests. Keep directory-fd sentinel and absolute-path handling unchanged.

Assisted-by: Codex:model-version-unavailable
  • Loading branch information
youknowdot committed Oct 8, 2026
commit 2572c59a9d5e071247837404419bcc71befbc581
4 changes: 4 additions & 0 deletions crates/host_env/src/fileutils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ pub use windows::{StatStruct, fstat};

#[cfg(not(windows))]
pub fn fstat(fd: crate::crt_fd::Borrowed<'_>) -> std::io::Result<StatStruct> {
// Unlike a directory fd, fstat accepts no negative descriptor sentinels.
if fd.as_raw() < 0 {
return Err(std::io::Error::from_raw_os_error(libc::EBADF));
}
rustix::fs::fstat(fd).map_err(Into::into)
}

Expand Down