Skip to content

Commit

Permalink
Auto merge of #1428 - RalfJung:shim-arg-size-verify, r=RalfJung
Browse files Browse the repository at this point in the history
verify the size of all shim arguments
  • Loading branch information
bors committed May 22, 2020
2 parents 427c8a6 + fbb8c15 commit 2bb96ff
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/shims/foreign_items/posix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -170,7 +170,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Dynamic symbol loading
"dlsym" => {
let &[handle, symbol] = check_arg_count(args)?;
this.read_scalar(handle)?.not_undef()?;
this.read_scalar(handle)?.to_machine_usize(this)?;
let symbol = this.read_scalar(symbol)?.not_undef()?;
let symbol_name = this.memory.read_c_str(symbol)?;
if let Some(dlsym) = Dlsym::from_str(symbol_name, &this.tcx.sess.target.target.target_os)? {
Expand Down Expand Up @@ -369,9 +369,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
}
"pthread_atfork" => {
let &[prepare, parent, child] = check_arg_count(args)?;
this.read_scalar(prepare)?.not_undef()?;
this.read_scalar(parent)?.not_undef()?;
this.read_scalar(child)?.not_undef()?;
this.force_bits(this.read_scalar(prepare)?.not_undef()?, this.memory.pointer_size())?;
this.force_bits(this.read_scalar(parent)?.not_undef()?, this.memory.pointer_size())?;
this.force_bits(this.read_scalar(child)?.not_undef()?, this.memory.pointer_size())?;
// We do not support forking, so there is nothing to do here.
this.write_null(dest)?;
}
Expand Down
4 changes: 2 additions & 2 deletions src/shims/foreign_items/posix/macos.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// Querying system information
"pthread_get_stackaddr_np" => {
let &[thread] = check_arg_count(args)?;
this.read_scalar(thread)?.not_undef()?;
this.read_scalar(thread)?.to_machine_usize(this)?;
let stack_addr = Scalar::from_uint(STACK_ADDR, this.pointer_size());
this.write_scalar(stack_addr, dest)?;
}
"pthread_get_stacksize_np" => {
let &[thread] = check_arg_count(args)?;
this.read_scalar(thread)?.not_undef()?;
this.read_scalar(thread)?.to_machine_usize(this)?;
let stack_size = Scalar::from_uint(STACK_SIZE, this.pointer_size());
this.write_scalar(stack_size, dest)?;
}
Expand Down
2 changes: 1 addition & 1 deletion src/shims/foreign_items/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
"GetProcAddress" => {
#[allow(non_snake_case)]
let &[hModule, lpProcName] = check_arg_count(args)?;
this.read_scalar(hModule)?.not_undef()?;
this.read_scalar(hModule)?.to_machine_isize(this)?;
let name = this.memory.read_c_str(this.read_scalar(lpProcName)?.not_undef()?)?;
if let Some(dlsym) = Dlsym::from_str(name, &this.tcx.sess.target.target.target_os)? {
let ptr = this.memory.create_fn_alloc(FnVal::Other(dlsym));
Expand Down

0 comments on commit 2bb96ff

Please sign in to comment.