Skip to content

Commit

Permalink
nit(sandbox): mild styling improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
n0toose committed Nov 28, 2024
1 parent 37c1eb3 commit cfaf8fb
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
11 changes: 2 additions & 9 deletions src/hypercall.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
7 changes: 3 additions & 4 deletions src/isolation.rs
Original file line number Diff line number Diff line change
@@ -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,
};
Expand Down Expand Up @@ -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(),
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit cfaf8fb

Please sign in to comment.