-
Notifications
You must be signed in to change notification settings - Fork 386
Check number of arguments for shims #1272
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
Comments
I'm curious how in practice can someone pass fewer or greater number of arguments, |
I wasn't talking about intrinsics. I was referring only to the foreign item shims. Sorry for not being clearer. |
So this for example:
Thanks for clarifying! |
Yes exactly. For the record, that example ICEs. extern "C" {
fn write(fd: i32, buf: *const u8, size: usize, extra: usize) -> usize;
}
fn main() {
let a = b"Hi\n\0";
unsafe {
write(1,a.as_ptr(),2,3);
}
} |
There's a proposed fix at #1298 thanks to @toc-the-younger |
@toc-the-younger you didn't just do this for the foreign items but even for intrinsics. That's great, but only half of our intrinsic implementations actually live in this repository -- the rest is in the rsutc repo so they do not have your check yet. Do you want to add the check there, too? |
@RalfJung Sure! I'll start on that today. |
Basically all our shims look something like this:
This code will ICE if the user passes fewer than 3 arguments, and it will silently "just work" if the user passes more than 3 arguments. To mitigate this, I propose we add a helper function
check_arg_count
or so that we call for each and every shim (foreign items and intrinsics) to raise an appropriate error (UB seems right) in case the number of arguments is wrong.(libstd-only shims that check
this.frame().instance
do not need checking.)The text was updated successfully, but these errors were encountered: