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/os.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/os.rs')
| -rw-r--r-- | src/libstd/sys/windows/os.rs | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/src/libstd/sys/windows/os.rs b/src/libstd/sys/windows/os.rs index 52740b2cad4..e2d2dc1a4de 100644 --- a/src/libstd/sys/windows/os.rs +++ b/src/libstd/sys/windows/os.rs @@ -28,6 +28,8 @@ use slice; use sys::{c, cvt}; use sys::handle::Handle; +use super::to_u16s; + pub fn errno() -> i32 { unsafe { c::GetLastError() as i32 } } @@ -228,7 +230,7 @@ pub fn chdir(p: &path::Path) -> io::Result<()> { } pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { - let k = super::to_utf16_os(k); + let k = try!(to_u16s(k)); let res = super::fill_utf16_buf(|buf, sz| unsafe { c::GetEnvironmentVariableW(k.as_ptr(), buf, sz) }, |buf| { @@ -247,8 +249,8 @@ pub fn getenv(k: &OsStr) -> io::Result<Option<OsString>> { } pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { - let k = super::to_utf16_os(k); - let v = super::to_utf16_os(v); + let k = try!(to_u16s(k)); + let v = try!(to_u16s(v)); cvt(unsafe { c::SetEnvironmentVariableW(k.as_ptr(), v.as_ptr()) @@ -256,7 +258,7 @@ pub fn setenv(k: &OsStr, v: &OsStr) -> io::Result<()> { } pub fn unsetenv(n: &OsStr) -> io::Result<()> { - let v = super::to_utf16_os(n); + let v = try!(to_u16s(n)); cvt(unsafe { c::SetEnvironmentVariableW(v.as_ptr(), ptr::null()) }).map(|_| ()) |
