From 65246bd48b070944e2a07535498a8c895da95e13 Mon Sep 17 00:00:00 2001 From: Jefferson Carpenter Date: Tue, 24 Mar 2020 08:02:34 +0000 Subject: [PATCH] kernelbase: Zero out retkey in the ERROR_INVALID_HANDLE case in RegOpenKeyExW Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48798 Signed-off-by: Jefferson Carpenter --- dlls/advapi32/tests/registry.c | 5 +++++ dlls/kernelbase/registry.c | 5 ++++- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c index e4d4893bd4..1f335b1c9f 100644 --- a/dlls/advapi32/tests/registry.c +++ b/dlls/advapi32/tests/registry.c @@ -1081,6 +1081,11 @@ static void test_reg_open_key(void) ok(!RegCloseKey(hkResult), "got invalid hkey\n"); /* empty subkey of NULL */ + hkResult = hkPreserve; + ret = RegOpenKeyExW(NULL, L"", 0, KEY_QUERY_VALUE, &hkResult); + ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", ret); + ok(hkResult == NULL || broken(hkResult == hkPreserve /* Windows XP */), "expected hkResult == NULL\n"); + hkResult = hkPreserve; ret = RegOpenKeyExA(NULL, "", 0, KEY_QUERY_VALUE, &hkResult); ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", ret); diff --git a/dlls/kernelbase/registry.c b/dlls/kernelbase/registry.c index e6f3722f70..dfd649269c 100644 --- a/dlls/kernelbase/registry.c +++ b/dlls/kernelbase/registry.c @@ -479,7 +479,10 @@ LSTATUS WINAPI DECLSPEC_HOTPATCH RegOpenKeyExW( HKEY hkey, LPCWSTR name, DWORD o if (HandleToUlong(hkey) == HandleToUlong(HKEY_CLASSES_ROOT) && name && *name == '\\') name++; if (!retkey) return ERROR_INVALID_PARAMETER; - if (!(hkey = get_special_root_hkey( hkey, access ))) return ERROR_INVALID_HANDLE; + if (!(hkey = get_special_root_hkey( hkey, access ))) { + *retkey = NULL; + return ERROR_INVALID_HANDLE; + } attr.Length = sizeof(attr); attr.RootDirectory = hkey; -- 2.23.0