Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 20 additions & 1 deletion library/std/src/sys/solid/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,26 @@ impl OpenOptions {
}

fn cstr(path: &Path) -> io::Result<CString> {
Ok(CString::new(path.as_os_str().as_bytes())?)
let path = path.as_os_str().as_bytes();

if !path.starts_with(br"\") {
// Relative paths aren't supported
return Err(crate::io::const_io_error!(
crate::io::ErrorKind::Unsupported,
"relative path is not supported on this platform",
));
}

// Apply the thread-safety wrapper
const SAFE_PREFIX: &[u8] = br"\TS";
let wrapped_path = [SAFE_PREFIX, &path, &[0]].concat();

CString::from_vec_with_nul(wrapped_path).map_err(|_| {
crate::io::const_io_error!(
io::ErrorKind::InvalidInput,
"path provided contains a nul byte",
)
})
}

impl File {
Expand Down