-
Notifications
You must be signed in to change notification settings - Fork 356
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?
Conversation
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.
Please squash
@rustbot author |
This comment has been minimized.
This comment has been minimized.
So now there is this weird function definition in this PR fn open(
&mut self,
args: &[OpTy<'tcx>],
fixed: &[OpTy<'tcx>; 2],
_var: &[OpTy<'tcx>],
) -> InterpResult<'tcx, Scalar> { where Since we already split fixed and var args through
It will lead to diagnostic like this: 11 | let _fd = unsafe { libc::open(name_ptr, libc::O_CREAT) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ incorrect number of arguments for `open(pathname, O_CREAT, ...)`: got 0, expected at least 1 Or maybe we can just ignore the fixed args and var args returned by |
Co-authored-by: Ralf Jung <[email protected]>
I would suggest to rename |
I didn't manage completely replace Lines 32 to 42 in c2a3761
I think as a miri specific extern function, the argument here shouldn't be classified as a vararg? |
src/shims/unix/foreign_items.rs
Outdated
@@ -207,8 +207,9 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { | |||
"fcntl" => { | |||
// `fcntl` is variadic. The argument count is checked based on the first argument |
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.
This comment looks weird, the argument count should be checked based on the second argument cmd
instead of the first? (source)
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.
Probably a copy-paste mistake.
@rustbot ready |
Oh dang. We have a comment in the docs for this function saying "The |
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.
I left some comments on the first place where you used the new infra; they apply everywhere in the PR.
@@ -928,6 +928,30 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> { | |||
interp_ok(()) | |||
} | |||
|
|||
/// Check the number of fixed args. |
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.
/// Check the number of fixed args. | |
/// Check the number of fixed args of a vararg function. |
This should probably error if the function is not a vararg fn?
Please also put "vararg" in the name then, e.g. check_vargarg_fixed_arg_count
.
(We used arg_count
before so please don't use args_count
here now.)
&'a [OpTy<'tcx>; N]: TryFrom<&'a [OpTy<'tcx>]>, | ||
{ | ||
self.check_abi_and_shim_symbol_clash(abi, exp_abi, link_name)?; | ||
self.check_fixed_args_count(shim_name, abi, args) |
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.
Why does this need self
when check_arg_count
does not?
@@ -1183,7 +1224,7 @@ where | |||
throw_ub_format!("incorrect number of arguments: got {}, expected {}", args.len(), N) | |||
} | |||
|
|||
/// Check that the number of args is at least the minumim what we expect. | |||
/// Check that the number of args is at least the minimum what we expect. |
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.
/// Check that the number of args is at least the minimum what we expect. | |
/// Check that the number of args is at least the minimum what we expect. | |
/// FIXME: Remove this function, use varargs and `check_min_vararg_count` instead. |
// We do not use `check_shim` here because `prctl` is variadic. The argument | ||
// count is checked bellow. | ||
ecx.check_abi_and_shim_symbol_clash(abi, Conv::C, link_name)?; | ||
// `prctl` is variadic. The argument count is checked below. |
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.
// `prctl` is variadic. The argument count is checked below. |
Not sure which value this comment still adds.
|
||
// FIXME: Use constants once https://github.com/rust-lang/libc/pull/3941 backported to the 0.2 branch. | ||
let pr_set_name = 15; | ||
let pr_get_name = 16; | ||
|
||
let [op] = check_min_arg_count("prctl", args)?; | ||
let [op] = fixed_args; |
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.
let [op] = fixed_args; |
let (fixed_args, varargs) = | ||
ecx.check_shim_variadic::<1>(abi, Conv::C, link_name, "prctl", args)?; |
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.
let (fixed_args, varargs) = | |
ecx.check_shim_variadic::<1>(abi, Conv::C, link_name, "prctl", args)?; | |
let ([op], varargs) = | |
ecx.check_shim_variadic(abi, Conv::C, link_name, "prctl", args)?; |
Same everywhere else -- you should never use turbofish here.
fn fcntl(&mut self, args: &[OpTy<'tcx>]) -> InterpResult<'tcx, Scalar> { | ||
fn fcntl( | ||
&mut self, | ||
fixed_args: &[OpTy<'tcx>; 2], |
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.
Instead of passing a 2-element array, just pass two arguments.
@rustbot author |
This PR added
check_shim_variadic
to be used by variadic function shimscheck_min_vararg_count
to retrieve varargs array from slicecheck_fixed_args_count
to check if we got expected number of fixed argscc #4013