From 133c2b39db73843e6a5ee0bce325cca034012579 Mon Sep 17 00:00:00 2001 From: Christian Poveda Date: Thu, 19 Sep 2019 10:32:18 -0500 Subject: [PATCH] Only use getcwd without isolation --- src/shims/env.rs | 32 +++++++++++++++++-------------- tests/run-pass/get_current_dir.rs | 1 + 2 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/shims/env.rs b/src/shims/env.rs index 73627086e0b..debeab894d4 100644 --- a/src/shims/env.rs +++ b/src/shims/env.rs @@ -119,22 +119,26 @@ fn getcwd( size_op: OpTy<'tcx, Tag>, ) -> InterpResult<'tcx, Scalar> { let this = self.eval_context_mut(); - let tcx = &{this.tcx.tcx}; - let buf = this.force_ptr(this.read_scalar(buf_op)?.not_undef()?)?; - let size = this.read_scalar(size_op)?.to_usize(&*this.tcx)?; - // If we cannot get the current directory, we return null - if let Ok(cwd) = env::current_dir() { - // It is not clear what happens with non-utf8 paths here - let mut bytes = cwd.display().to_string().into_bytes(); - // If the buffer is smaller than the path, we return null - if bytes.len() as u64 <= size { - // We need `size` bytes exactly - bytes.resize(size as usize, 0); - this.memory_mut().get_mut(buf.alloc_id)?.write_bytes(tcx, buf, &bytes)?; - return Ok(Scalar::Ptr(buf)) + if this.machine.communicate { + let tcx = &{this.tcx.tcx}; + + let buf = this.force_ptr(this.read_scalar(buf_op)?.not_undef()?)?; + let size = this.read_scalar(size_op)?.to_usize(&*this.tcx)?; + // If we cannot get the current directory, we return null + if let Ok(cwd) = env::current_dir() { + // It is not clear what happens with non-utf8 paths here + let mut bytes = cwd.display().to_string().into_bytes(); + // If the buffer is smaller than the path, we return null + if bytes.len() as u64 <= size { + // We need `size` bytes exactly + bytes.resize(size as usize, 0); + this.memory_mut().get_mut(buf.alloc_id)?.write_bytes(tcx, buf, &bytes)?; + return Ok(Scalar::Ptr(buf)) + } } + return Ok(Scalar::ptr_null(&*this.tcx)); } - Ok(Scalar::ptr_null(&*this.tcx)) + throw_unsup_format!("Function not available when isolation is enabled") } } diff --git a/tests/run-pass/get_current_dir.rs b/tests/run-pass/get_current_dir.rs index d8e6c225e96..45efd06d3f6 100644 --- a/tests/run-pass/get_current_dir.rs +++ b/tests/run-pass/get_current_dir.rs @@ -1,4 +1,5 @@ // ignore-windows: TODO the windows hook is not done yet +// compile-flags: -Zmiri-disable-isolation fn main() { std::env::current_dir().unwrap(); -- 2.44.0