Vladimir Panteleev : kernelbase: Don't return ERROR_INSUFFICIENT_BUFFER from GetEnvironmentVariableW.
Alexandre Julliard
julliard at winehq.org
Fri Aug 7 10:42:29 CDT 2020
Module: wine
Branch: stable
Commit: 796a392f7f9f63b36a7243f45808d82df5279afd
URL: https://source.winehq.org/git/wine.git/?a=commit;h=796a392f7f9f63b36a7243f45808d82df5279afd
Author: Vladimir Panteleev <git at vladimir.panteleev.md>
Date: Thu May 14 23:12:25 2020 +0200
kernelbase: Don't return ERROR_INSUFFICIENT_BUFFER from GetEnvironmentVariableW.
Windows doesn't do this (except XP, and then only for empty variables,
where it returns ERROR_MORE_DATA).
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48471
Signed-off-by: Vladimir Panteleev <git at vladimir.panteleev.md>
Signed-off-by: Gijs Vermeulen <gijsvrm at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
(cherry picked from commit 4c06599c1ff3767cc8d70d7de9269c424900c3a4)
Signed-off-by: Michael Stefaniuc <mstefani at winehq.org>
---
dlls/kernel32/tests/environ.c | 6 ++++++
dlls/kernelbase/process.c | 3 ++-
2 files changed, 8 insertions(+), 1 deletion(-)
diff --git a/dlls/kernel32/tests/environ.c b/dlls/kernel32/tests/environ.c
index 561fc71c4c..ff822d0349 100644
--- a/dlls/kernel32/tests/environ.c
+++ b/dlls/kernel32/tests/environ.c
@@ -104,9 +104,12 @@ static void test_GetSetEnvironmentVariableA(void)
GetLastError());
/* Try to retrieve the environment variable we just set */
+ SetLastError(0xdeadbeef);
ret_size = GetEnvironmentVariableA(name, NULL, 0);
ok(ret_size == strlen(value) + 1,
"should return length with terminating 0 ret_size=%d\n", ret_size);
+ ok(GetLastError() == 0xdeadbeef,
+ "should not fail with zero size but GetLastError=%d\n", GetLastError());
lstrcpyA(buf, "foo");
ret_size = GetEnvironmentVariableA(name, buf, lstrlenA(value));
@@ -206,10 +209,13 @@ static void test_GetSetEnvironmentVariableW(void)
GetLastError());
/* Try to retrieve the environment variable we just set */
+ SetLastError(0xdeadbeef);
ret_size = GetEnvironmentVariableW(name, NULL, 0);
ok(ret_size == lstrlenW(value) + 1,
"should return length with terminating 0 ret_size=%d\n",
ret_size);
+ ok(GetLastError() == 0xdeadbeef,
+ "should not fail with zero size but GetLastError=%d\n", GetLastError());
lstrcpyW(buf, fooW);
ret_size = GetEnvironmentVariableW(name, buf, lstrlenW(value));
diff --git a/dlls/kernelbase/process.c b/dlls/kernelbase/process.c
index 76fe699b8a..ec8b6eabab 100644
--- a/dlls/kernelbase/process.c
+++ b/dlls/kernelbase/process.c
@@ -1282,7 +1282,8 @@ DWORD WINAPI DECLSPEC_HOTPATCH GetEnvironmentVariableW( LPCWSTR name, LPWSTR val
status = RtlQueryEnvironmentVariable_U( NULL, &us_name, &us_value );
len = us_value.Length / sizeof(WCHAR);
- if (!set_ntstatus( status )) return (status == STATUS_BUFFER_TOO_SMALL) ? len + 1 : 0;
+ if (status == STATUS_BUFFER_TOO_SMALL) return len + 1;
+ if (!set_ntstatus( status )) return 0;
if (size) val[len] = 0;
return len;
}
More information about the wine-cvs
mailing list