diff --git a/src/hypercall.rs b/src/hypercall.rs index 299001ae..7eaa3fa6 100644 --- a/src/hypercall.rs +++ b/src/hypercall.rs @@ -106,16 +106,9 @@ pub fn open( ) { // TODO: Keep track of file descriptors internally, just in case the kernel doesn't close them. let requested_path_ptr = mem.host_address(sysopen.name).unwrap() as *const i8; - let guest_path = unsafe { CStr::from_ptr(requested_path_ptr) }.to_str(); let mut flags = sysopen.flags & ALLOWED_OPEN_FLAGS; - - if let Ok(guest_path) = guest_path { - // Rust deals in UTF-8. C doesn't provide such a guarantee. - // In that case, converting a CStr to str will return a Utf8Error. - // - // See: https://nrc.github.io/big-book-ffi/reference/strings.html - let host_path_option = file_map.get_host_path(guest_path); - if let Some(host_path) = host_path_option { + if let Ok(guest_path) = unsafe { CStr::from_ptr(requested_path_ptr) }.to_str() { + if let Some(host_path) = file_map.get_host_path(guest_path) { // We can safely unwrap here, as host_path.as_bytes will never contain internal \0 bytes // As host_path_c_string is a valid CString, this implementation is presumed to be safe. let host_path_c_string = CString::new(host_path.as_bytes()).unwrap(); diff --git a/src/isolation.rs b/src/isolation.rs index 2839bfe4..cf4babb4 100644 --- a/src/isolation.rs +++ b/src/isolation.rs @@ -1,8 +1,7 @@ use std::{ collections::HashMap, ffi::{CString, OsString}, - fs, - fs::Permissions, + fs::{canonicalize, Permissions}, os::unix::{ffi::OsStrExt, fs::PermissionsExt}, path::PathBuf, }; @@ -45,7 +44,7 @@ impl UhyveFileMap { .map(|(guest_path, host_path)| { ( guest_path, - fs::canonicalize(&host_path).map_or(host_path, PathBuf::into_os_string), + canonicalize(&host_path).map_or(host_path, PathBuf::into_os_string), ) }) .collect(), @@ -96,7 +95,7 @@ impl UhyveFileMap { host_path.push(guest_path_remainder); // Handles symbolic links. - return fs::canonicalize(&host_path) + return canonicalize(&host_path) .map_or(host_path.into_os_string(), PathBuf::into_os_string) .into(); }