From 3a9f4eed937677596a0269399178d274ee7c446e Mon Sep 17 00:00:00 2001 From: Jefferson Carpenter Date: Thu, 26 Mar 2020 08:59:22 +0000 Subject: [PATCH] kernelbase: Zero out retkey in the ERROR_INVALID_HANDLE case in RegOpenKeyExW --- dlls/advapi32/tests/registry.c | 10 ++++++++++ dlls/kernelbase/registry.c | 6 +++++- 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c index e4d4893bd4..2c60abc446 100644 --- a/dlls/advapi32/tests/registry.c +++ b/dlls/advapi32/tests/registry.c @@ -1081,6 +1081,16 @@ 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); + if (LOBYTE(LOWORD(GetVersion())) < 6) { + ok(hkResult == hkPreserve, "expected hkResult == hPreserve\n"); + } + else { + ok(hkResult == NULL, "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..2861e37800 100644 --- a/dlls/kernelbase/registry.c +++ b/dlls/kernelbase/registry.c @@ -479,7 +479,11 @@ 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 ))) { + if (LOBYTE(LOWORD(GetVersion())) >= 6) + *retkey = NULL; + return ERROR_INVALID_HANDLE; + } attr.Length = sizeof(attr); attr.RootDirectory = hkey; -- 2.23.0