Skip to content

Commit 2bb96ff

Browse files
committed
Auto merge of #1428 - RalfJung:shim-arg-size-verify, r=RalfJung
verify the size of all shim arguments
2 parents 427c8a6 + fbb8c15 commit 2bb96ff

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

src/shims/foreign_items/posix.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
170170
// Dynamic symbol loading
171171
"dlsym" => {
172172
let &[handle, symbol] = check_arg_count(args)?;
173-
this.read_scalar(handle)?.not_undef()?;
173+
this.read_scalar(handle)?.to_machine_usize(this)?;
174174
let symbol = this.read_scalar(symbol)?.not_undef()?;
175175
let symbol_name = this.memory.read_c_str(symbol)?;
176176
if let Some(dlsym) = Dlsym::from_str(symbol_name, &this.tcx.sess.target.target.target_os)? {
@@ -369,9 +369,9 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
369369
}
370370
"pthread_atfork" => {
371371
let &[prepare, parent, child] = check_arg_count(args)?;
372-
this.read_scalar(prepare)?.not_undef()?;
373-
this.read_scalar(parent)?.not_undef()?;
374-
this.read_scalar(child)?.not_undef()?;
372+
this.force_bits(this.read_scalar(prepare)?.not_undef()?, this.memory.pointer_size())?;
373+
this.force_bits(this.read_scalar(parent)?.not_undef()?, this.memory.pointer_size())?;
374+
this.force_bits(this.read_scalar(child)?.not_undef()?, this.memory.pointer_size())?;
375375
// We do not support forking, so there is nothing to do here.
376376
this.write_null(dest)?;
377377
}

src/shims/foreign_items/posix/macos.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,13 +105,13 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
105105
// Querying system information
106106
"pthread_get_stackaddr_np" => {
107107
let &[thread] = check_arg_count(args)?;
108-
this.read_scalar(thread)?.not_undef()?;
108+
this.read_scalar(thread)?.to_machine_usize(this)?;
109109
let stack_addr = Scalar::from_uint(STACK_ADDR, this.pointer_size());
110110
this.write_scalar(stack_addr, dest)?;
111111
}
112112
"pthread_get_stacksize_np" => {
113113
let &[thread] = check_arg_count(args)?;
114-
this.read_scalar(thread)?.not_undef()?;
114+
this.read_scalar(thread)?.to_machine_usize(this)?;
115115
let stack_size = Scalar::from_uint(STACK_SIZE, this.pointer_size());
116116
this.write_scalar(stack_size, dest)?;
117117
}

src/shims/foreign_items/windows.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
210210
"GetProcAddress" => {
211211
#[allow(non_snake_case)]
212212
let &[hModule, lpProcName] = check_arg_count(args)?;
213-
this.read_scalar(hModule)?.not_undef()?;
213+
this.read_scalar(hModule)?.to_machine_isize(this)?;
214214
let name = this.memory.read_c_str(this.read_scalar(lpProcName)?.not_undef()?)?;
215215
if let Some(dlsym) = Dlsym::from_str(name, &this.tcx.sess.target.target.target_os)? {
216216
let ptr = this.memory.create_fn_alloc(FnVal::Other(dlsym));

0 commit comments

Comments
 (0)