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
Prev Previous commit
Next Next commit
Cover negative stat descriptors through the interpreter
Exercise ordinary negative descriptors including values accepted by rustix as directory sentinels, without changing canonical tests or directory-fd parsing.

Assisted-by: Codex:model-version-unavailable
  • Loading branch information
youknowdot committed Oct 8, 2026
commit 30a1e45a7fbd07b75b3e832e7cdf896eb0485cc5
30 changes: 30 additions & 0 deletions tests/negative_fstat.rs

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do not add python test code in rust file

Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#![allow(clippy::tests_outside_test_module)]

#[cfg(unix)]
#[test]
fn stat_rejects_negative_file_descriptors() {
use rustpython::{InterpreterBuilder, InterpreterBuilderExt};

InterpreterBuilder::new()
.init_stdlib()
.interpreter()
.enter(|vm| {
let source = r#"
import errno
import os

for stat in (os.stat, os.fstat):
for fd in (-1, -5, -9, -100, -(2**31)):
try:
stat(fd)
except OSError as exc:
assert exc.errno == errno.EBADF, (stat, fd, exc)
else:
raise AssertionError((stat, fd, 'accepted a negative file descriptor'))
"#;
if let Err(err) = vm.run_simple_string(source) {
vm.print_exception(&err);
panic!("negative descriptor regression failed");
}
});
}
Loading