-
Notifications
You must be signed in to change notification settings - Fork 355
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Check fixed args number for variadic function #4122
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -208,6 +208,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { | |
// `fcntl` is variadic. The argument count is checked based on the first argument | ||
// in `this.fcntl()`, so we do not use `check_shim` here. | ||
this.check_abi_and_shim_symbol_clash(abi, Conv::C , link_name)?; | ||
this.check_fixed_args_count("fcntl", abi, 2)?; | ||
let result = this.fcntl(args)?; | ||
this.write_scalar(result, dest)?; | ||
} | ||
|
@@ -236,6 +237,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { | |
"open" | "open64" => { | ||
// `open` is variadic, the third argument is only present when the second argument has O_CREAT (or on linux O_TMPFILE, but miri doesn't support that) set | ||
this.check_abi_and_shim_symbol_clash(abi, Conv::C , link_name)?; | ||
this.check_fixed_args_count("open/open64", abi, 2)?; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Now it's still fairly easy to forget to call So instead, please add a new When this is all done, |
||
let result = this.open(args)?; | ||
this.write_scalar(result, dest)?; | ||
} | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
//@ignore-target: windows # File handling is not implemented yet | ||
//@compile-flags: -Zmiri-disable-isolation | ||
use std::ffi::{CString, OsStr}; | ||
use std::os::unix::ffi::OsStrExt; | ||
|
||
extern "C" { | ||
fn open(path: *const libc::c_char, ...) -> libc::c_int; | ||
} | ||
|
||
fn main() { | ||
let c_path = CString::new(OsStr::new("./text").as_bytes()).expect("CString::new failed"); | ||
let _fd = unsafe { open(c_path.as_ptr(), libc::O_RDWR) }; | ||
//~^ ERROR: incorrect number of fixed args | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
error: Undefined Behavior: incorrect number of fixed args for `open/open64`: got 1, expected 2 | ||
--> tests/fail-dep/libc/wrong_fixed_arg_count.rs:LL:CC | ||
| | ||
LL | let _fd = unsafe { open(c_path.as_ptr(), libc::O_RDWR) }; | ||
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of fixed args for `open/open64`: got 1, expected 2 | ||
| | ||
= help: this indicates a bug in the program: it performed an invalid operation, and caused Undefined Behavior | ||
= help: see https://doc.rust-lang.org/nightly/reference/behavior-considered-undefined.html for further information | ||
= note: BACKTRACE: | ||
= note: inside `main` at tests/fail-dep/libc/wrong_fixed_arg_count.rs:LL:CC | ||
|
||
note: some details are omitted, run with `MIRIFLAGS=-Zmiri-backtrace=full` for a verbose backtrace | ||
|
||
error: aborting due to 1 previous error | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.