Skip to content

Commit 40800cf

Browse files
committed
make sure we check the size of all arguments
1 parent 5656cb7 commit 40800cf

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

src/shims/foreign_items/posix.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
3434
this.write_scalar(Scalar::from_i32(result), dest)?;
3535
}
3636
"setenv" => {
37-
let &[name, value, _overwrite] = check_arg_count(args)?;
37+
let &[name, value, overwrite] = check_arg_count(args)?;
38+
this.read_scalar(overwrite)?.to_i32()?;
3839
let result = this.setenv(name, value)?;
3940
this.write_scalar(Scalar::from_i32(result), dest)?;
4041
}
@@ -51,8 +52,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
5152

5253
// File related shims
5354
"open" | "open64" => {
54-
let &[path, flag, _mode] = check_arg_count(args)?;
55-
let result = this.open(path, flag)?;
55+
let &[path, flag, mode] = check_arg_count(args)?;
56+
let result = this.open(path, flag, mode)?;
5657
this.write_scalar(Scalar::from_i32(result), dest)?;
5758
}
5859
"fcntl" => {

src/shims/foreign_items/windows.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,8 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
6363
this.write_scalar(Scalar::from_machine_isize(which.into(), this), dest)?;
6464
}
6565
"WriteFile" => {
66-
let &[handle, buf, n, written_ptr, _overlapped] = check_arg_count(args)?;
66+
let &[handle, buf, n, written_ptr, overlapped] = check_arg_count(args)?;
67+
this.read_scalar(overlapped)?.to_machine_usize(this)?; // this is a poiner, that we ignore
6768
let handle = this.read_scalar(handle)?.to_machine_isize(this)?;
6869
let buf = this.read_scalar(buf)?.not_undef()?;
6970
let n = this.read_scalar(n)?.to_u32()?;

src/shims/fs.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,13 +238,27 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
238238
&mut self,
239239
path_op: OpTy<'tcx, Tag>,
240240
flag_op: OpTy<'tcx, Tag>,
241+
mode_op: OpTy<'tcx, Tag>,
241242
) -> InterpResult<'tcx, i32> {
242243
let this = self.eval_context_mut();
243244

244245
this.check_no_isolation("open")?;
245246

246247
let flag = this.read_scalar(flag_op)?.to_i32()?;
247248

249+
// Check mode (size depends on platform).
250+
// FIXME: should we do something with the mode?
251+
match this.tcx.sess.target.target.target_os.as_str() {
252+
"macos" => {
253+
// FIXME: I think `mode` should be `u16` on macOS, but see
254+
// <https://github.com/rust-lang/rust/issues/71915>.
255+
// For now, just don't check on macos.
256+
}
257+
_ => {
258+
this.read_scalar(mode_op)?.to_u32()?;
259+
}
260+
};
261+
248262
let mut options = OpenOptions::new();
249263

250264
let o_rdonly = this.eval_libc_i32("O_RDONLY")?;

0 commit comments

Comments
 (0)