diff options
| author | Tobias Bucher <tobiasbucher5991@gmail.com> | 2015-11-19 18:01:11 +0000 |
|---|---|---|
| committer | Tobias Bucher <tobiasbucher5991@gmail.com> | 2015-11-21 01:11:15 +0000 |
| commit | 71dccf8706ab25f75667c1cbb85ce94f2decbb57 (patch) | |
| tree | ae32a75493b7711f57ad58dd7f8968b0f427a2e7 /src/libstd/sys/windows/mod.rs | |
| parent | 06fab0ea7002bde57beaee6db7976ae0cb080c38 (diff) | |
| download | rust-71dccf8706ab25f75667c1cbb85ce94f2decbb57.tar.gz rust-71dccf8706ab25f75667c1cbb85ce94f2decbb57.zip | |
Also check for NULs in environment variables
This check is necessary, because the underlying API only reads strings until the first NUL.
Diffstat (limited to 'src/libstd/sys/windows/mod.rs')
| -rw-r--r-- | src/libstd/sys/windows/mod.rs | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/libstd/sys/windows/mod.rs b/src/libstd/sys/windows/mod.rs index 3f76218eafe..7e5342a3fd4 100644 --- a/src/libstd/sys/windows/mod.rs +++ b/src/libstd/sys/windows/mod.rs @@ -72,10 +72,17 @@ pub fn decode_error_kind(errno: i32) -> ErrorKind { } } -fn to_utf16_os(s: &OsStr) -> Vec<u16> { - let mut v: Vec<_> = s.encode_wide().collect(); - v.push(0); - v +pub fn to_u16s<S: AsRef<OsStr>>(s: S) -> io::Result<Vec<u16>> { + fn inner(s: &OsStr) -> io::Result<Vec<u16>> { + let mut maybe_result: Vec<u16> = s.encode_wide().collect(); + if maybe_result.iter().any(|&u| u == 0) { + return Err(io::Error::new(io::ErrorKind::InvalidInput, + "strings passed to WinAPI cannot contain NULs")); + } + maybe_result.push(0); + Ok(maybe_result) + } + inner(s.as_ref()) } // Many Windows APIs follow a pattern of where we hand a buffer and then they |
