From 413ca98d9110404d745471e54af10fc950292417 Mon Sep 17 00:00:00 2001 From: Eugene Talagrand Date: Sat, 16 Oct 2021 18:23:42 -1000 Subject: Update std::env::temp_dir to use GetTempPath2 on Windows when available. As a security measure, Windows 11 introduces a new temporary directory API, GetTempPath2. When the calling process is running as SYSTEM, a separate temporary directory will be returned inaccessible to non-SYSTEM processes. For non-SYSTEM processes the behavior will be the same as before. --- library/std/src/sys/windows/c.rs | 6 ++++++ library/std/src/sys/windows/os.rs | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) (limited to 'library/std/src/sys') diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index e5c550802a7..87add8b0874 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -1102,6 +1102,12 @@ compat_fn! { -> () { GetSystemTimeAsFileTime(lpSystemTimeAsFileTime) } + + // >= Win11 + // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a + pub fn GetTempPath2W(nBufferLength: DWORD, lpBuffer: LPCWSTR) -> DWORD { + GetTempPathW(nBufferLength, lpBuffer) + } } compat_fn! { diff --git a/library/std/src/sys/windows/os.rs b/library/std/src/sys/windows/os.rs index 883690c4831..0c26321c47d 100644 --- a/library/std/src/sys/windows/os.rs +++ b/library/std/src/sys/windows/os.rs @@ -275,7 +275,7 @@ pub fn unsetenv(n: &OsStr) -> io::Result<()> { } pub fn temp_dir() -> PathBuf { - super::fill_utf16_buf(|buf, sz| unsafe { c::GetTempPathW(sz, buf) }, super::os2path).unwrap() + super::fill_utf16_buf(|buf, sz| unsafe { c::GetTempPath2W(sz, buf) }, super::os2path).unwrap() } #[cfg(not(target_vendor = "uwp"))] -- cgit 1.4.1-3-g733a5 From 1d26e413de7a026ae2e99dad82edd2b8affcf5f3 Mon Sep 17 00:00:00 2001 From: Eugene Talagrand Date: Tue, 26 Oct 2021 17:49:55 -0700 Subject: Clarify platform availability of GetTempPath2 Windows Server 2022 is a different version from Win11, breaking precent --- library/std/src/sys/windows/c.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'library/std/src/sys') diff --git a/library/std/src/sys/windows/c.rs b/library/std/src/sys/windows/c.rs index 87add8b0874..b9f49fed769 100644 --- a/library/std/src/sys/windows/c.rs +++ b/library/std/src/sys/windows/c.rs @@ -1103,7 +1103,7 @@ compat_fn! { GetSystemTimeAsFileTime(lpSystemTimeAsFileTime) } - // >= Win11 + // >= Win11 / Server 2022 // https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-gettemppath2a pub fn GetTempPath2W(nBufferLength: DWORD, lpBuffer: LPCWSTR) -> DWORD { GetTempPathW(nBufferLength, lpBuffer) -- cgit 1.4.1-3-g733a5