Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions library/std/src/sys/paths/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,11 @@ where
joined.push(sep)
}
let v = path.encode_wide().collect::<Vec<u16>>();
if v.contains(&(b'"' as u16)) {
// Interior NULs would truncate when the joined string is later passed to
// WinAPI / environment blocks as a C-style wide string (e.g. PATH).
if v.contains(&0) {
return Err(JoinPathsError);
} else if v.contains(&(b'"' as u16)) {
return Err(JoinPathsError);
} else if v.contains(&sep) {
joined.push(b'"' as u16);
Expand All @@ -89,7 +93,7 @@ where

impl fmt::Display for JoinPathsError {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
"path segment contains `\"`".fmt(f)
"path segment contains `\"` or interior NUL".fmt(f)
}
}

Expand Down