diff options
| author | Chris Denton <christophersdenton@gmail.com> | 2022-03-25 04:28:24 +0000 |
|---|---|---|
| committer | Chris Denton <christophersdenton@gmail.com> | 2022-03-25 18:03:03 +0000 |
| commit | 7200afaadb8a0afcf09906023eb68480a1edec3c (patch) | |
| tree | 7859df4b6cca59255328066e738f476e73622aae | |
| parent | 9270ca193f58d287d75f0115c59667792cec1e19 (diff) | |
| download | rust-7200afaadb8a0afcf09906023eb68480a1edec3c.tar.gz rust-7200afaadb8a0afcf09906023eb68480a1edec3c.zip | |
Check for `"` and `\` in a filename
And also fix typo.
| -rw-r--r-- | library/std/src/sys/windows/args.rs | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/library/std/src/sys/windows/args.rs b/library/std/src/sys/windows/args.rs index 1d3d3013e7e..c5918103fec 100644 --- a/library/std/src/sys/windows/args.rs +++ b/library/std/src/sys/windows/args.rs @@ -307,12 +307,20 @@ pub(crate) fn make_bat_command_line( ) -> io::Result<Vec<u16>> { // Set the start of the command line to `cmd.exe /c "` // It is necessary to surround the command in an extra pair of quotes, - // hence The trailing quote here. It will be closed after all arguments + // hence the trailing quote here. It will be closed after all arguments // have been added. let mut cmd: Vec<u16> = "cmd.exe /c \"".encode_utf16().collect(); // Push the script name surrounded by its quote pair. cmd.push(b'"' as u16); + // Windows file names cannot contain a `"` character or end with `\\`. + // If the script name does then return an error. + if script.contains(&(b'"' as u16)) || script.last() == Some(&(b'\\' as u16)) { + return Err(io::const_io_error!( + io::ErrorKind::InvalidInput, + "Windows file names may not contain `\"` or end with `\\`" + )); + } cmd.extend_from_slice(script.strip_suffix(&[0]).unwrap_or(script)); cmd.push(b'"' as u16); |
