]> git.lizzy.rs Git - rust.git/commitdiff
make sure we check the size of all arguments
authorRalf Jung <post@ralfj.de>
Tue, 5 May 2020 10:19:54 +0000 (12:19 +0200)
committerRalf Jung <post@ralfj.de>
Tue, 5 May 2020 10:19:54 +0000 (12:19 +0200)
src/shims/foreign_items/posix.rs
src/shims/foreign_items/windows.rs
src/shims/fs.rs

index a68414ddbc2fe7668ea25c5276acadff186c6690..951a40293b72d834615b25b5e03f8808b3a4bc9f 100644 (file)
@@ -34,7 +34,8 @@ fn emulate_foreign_item_by_name(
                 this.write_scalar(Scalar::from_i32(result), dest)?;
             }
             "setenv" => {
-                let &[name, value, _overwrite] = check_arg_count(args)?;
+                let &[name, value, overwrite] = check_arg_count(args)?;
+                this.read_scalar(overwrite)?.to_i32()?;
                 let result = this.setenv(name, value)?;
                 this.write_scalar(Scalar::from_i32(result), dest)?;
             }
@@ -51,8 +52,8 @@ fn emulate_foreign_item_by_name(
 
             // File related shims
             "open" | "open64" => {
-                let &[path, flag, _mode] = check_arg_count(args)?;
-                let result = this.open(path, flag)?;
+                let &[path, flag, mode] = check_arg_count(args)?;
+                let result = this.open(path, flag, mode)?;
                 this.write_scalar(Scalar::from_i32(result), dest)?;
             }
             "fcntl" => {
index cff1887ff8b54327f7a090abb83bb284b0addc37..7f3cd03cd2d36fcf841e142f889eac1b0c38fd9a 100644 (file)
@@ -63,7 +63,8 @@ fn emulate_foreign_item_by_name(
                 this.write_scalar(Scalar::from_machine_isize(which.into(), this), dest)?;
             }
             "WriteFile" => {
-                let &[handle, buf, n, written_ptr, _overlapped] = check_arg_count(args)?;
+                let &[handle, buf, n, written_ptr, overlapped] = check_arg_count(args)?;
+                this.read_scalar(overlapped)?.to_machine_usize(this)?; // this is a poiner, that we ignore
                 let handle = this.read_scalar(handle)?.to_machine_isize(this)?;
                 let buf = this.read_scalar(buf)?.not_undef()?;
                 let n = this.read_scalar(n)?.to_u32()?;
index ba4611373c8a0e14065ca0eed47fd9064473cad3..58abf748dd5a86179edd5615abde96ef0f630657 100644 (file)
@@ -238,6 +238,7 @@ fn open(
         &mut self,
         path_op: OpTy<'tcx, Tag>,
         flag_op: OpTy<'tcx, Tag>,
+        mode_op: OpTy<'tcx, Tag>,
     ) -> InterpResult<'tcx, i32> {
         let this = self.eval_context_mut();
 
@@ -245,6 +246,19 @@ fn open(
 
         let flag = this.read_scalar(flag_op)?.to_i32()?;
 
+        // Check mode (size depends on platform).
+        // FIXME: should we do something with the mode?
+        match this.tcx.sess.target.target.target_os.as_str() {
+            "macos" => {
+                // FIXME: I think `mode` should be `u16` on macOS, but see
+                // <https://github.com/rust-lang/rust/issues/71915>.
+                // For now, just don't check on macos.
+            }
+            _ => {
+                this.read_scalar(mode_op)?.to_u32()?;
+            }
+        };
+
         let mut options = OpenOptions::new();
 
         let o_rdonly = this.eval_libc_i32("O_RDONLY")?;