Skip to content

Commit

Permalink
Rename write/read os string functions
Browse files Browse the repository at this point in the history
  • Loading branch information
pvdrz committed Oct 18, 2019
1 parent 68fec4b commit 85941c7
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/helpers.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,12 +346,12 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
Ok(())
}

fn read_os_string(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx, OsString> {
fn read_os_string_from_c_string(&mut self, scalar: Scalar<Tag>) -> InterpResult<'tcx, OsString> {
let bytes = self.eval_context_mut().memory.read_c_str(scalar)?;
Ok(bytes_to_os_str(bytes)?.into())
}

fn write_os_str(&mut self, os_str: &OsStr, ptr: Pointer<Tag>, size: u64) -> InterpResult<'tcx> {
fn write_os_str_to_c_string(&mut self, os_str: &OsStr, ptr: Pointer<Tag>, size: u64) -> InterpResult<'tcx> {
let bytes = os_str_to_bytes(os_str)?;
// If `size` is smaller or equal than `bytes.len()`, writing `bytes` plus the required null
// terminator to memory using the `ptr` pointer would cause an overflow.
Expand Down
4 changes: 2 additions & 2 deletions src/shims/env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
// If we cannot get the current directory, we return null
match env::current_dir() {
Ok(cwd) => {
if this.write_os_str(&OsString::from(cwd), buf, size).is_ok() {
if this.write_os_str_to_c_string(&OsString::from(cwd), buf, size).is_ok() {
return Ok(Scalar::Ptr(buf));
}
let erange = this.eval_libc("ERANGE")?;
Expand All @@ -144,7 +144,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx

this.check_no_isolation("chdir")?;

let path = this.read_os_string(this.read_scalar(path_op)?.not_undef()?)?;
let path = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?;

match env::set_current_dir(path) {
Ok(()) => Ok(0),
Expand Down
8 changes: 2 additions & 6 deletions src/shims/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
throw_unsup_format!("unsupported flags {:#x}", flag & !mirror);
}

let path: std::path::PathBuf = this.read_os_string(this.read_scalar(path_op)?.not_undef()?)?.into();
let path: std::path::PathBuf = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?.into();

let fd = options.open(path).map(|file| {
let mut fh = &mut this.machine.file_handler;
Expand Down Expand Up @@ -210,11 +210,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx

this.check_no_isolation("unlink")?;

let path_bytes = this
.memory
.read_c_str(this.read_scalar(path_op)?.not_undef()?)?;
let path = std::str::from_utf8(path_bytes)
.map_err(|_| err_unsup_format!("{:?} is not a valid utf-8 string", path_bytes))?;
let path = this.read_os_string_from_c_string(this.read_scalar(path_op)?.not_undef()?)?;

let result = remove_file(path).map(|_| 0);

Expand Down

0 comments on commit 85941c7

Please sign in to comment.