[PATCH v2] kernel32: make GetEnvironmentStringsW returns a copy of the environment
There are certain applications which try to traverse the environement being returned, but this is problematic since they cannot acquire the PEB Lock (i.e cl.exe on Visual Studio 14.15) . To resolve the issue provide a copy of the current environment same as in GetEnvironmentStringsA . Signed-off-by: Jon Doron <arilou(a)gmail.com> --- dlls/kernel32/environ.c | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/dlls/kernel32/environ.c b/dlls/kernel32/environ.c index 99bf706e95..5a5f50340e 100644 --- a/dlls/kernel32/environ.c +++ b/dlls/kernel32/environ.c @@ -139,7 +139,30 @@ LPSTR WINAPI GetEnvironmentStringsA(void) */ LPWSTR WINAPI GetEnvironmentStringsW(void) { - return NtCurrentTeb()->Peb->ProcessParameters->Environment; + LPWSTR ret, ptrW; + unsigned len; + + RtlAcquirePebLock(); + + ptrW = NtCurrentTeb()->Peb->ProcessParameters->Environment; + if (!ptrW || !*ptrW) + { + RtlReleasePebLock(); + return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, sizeof(WCHAR) * 2); + } + + while (*ptrW) + ptrW += strlenW(ptrW) + 1; + + len = (ULONG_PTR)ptrW - (ULONG_PTR)NtCurrentTeb()->Peb->ProcessParameters->Environment; + ret = HeapAlloc(GetProcessHeap(), 0, len + sizeof(WCHAR)); + if (ret) { + memcpy(ret, NtCurrentTeb()->Peb->ProcessParameters->Environment, len); + ret[len / 2] = 0; + } + + RtlReleasePebLock(); + return ret; } @@ -157,7 +180,7 @@ BOOL WINAPI FreeEnvironmentStringsA( LPSTR ptr ) */ BOOL WINAPI FreeEnvironmentStringsW( LPWSTR ptr ) { - return TRUE; + return HeapFree( GetProcessHeap(), 0, ptr ); } -- 2.19.2
Hi, While running your changed tests, I think I found new failures. Being a bot and all I'm not very good at pattern recognition, so I might be wrong, but could you please double-check? Full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=49505 Your paranoid android. === debian9 (32 bit report) === kernel32: change.c:320: Test failed: should be ready
participants (2)
-
Jon Doron -
Marvin