From 0824d7d8ee22513e3fa98a46ad6ec132936176ca Mon Sep 17 00:00:00 2001 From: Jefferson Carpenter Date: Tue, 24 Mar 2020 06:46:38 +0000 Subject: [PATCH] kernelbase: Zero out retkey in the ERROR_INVALID_HANDLE case in RegOpenKeyEx Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48798 Signed-off-by: Jefferson Carpenter --- dlls/kernelbase/registry.c | 5 +++- dlls/kernelbase/tests/Makefile.in | 1 + dlls/kernelbase/tests/registry.c | 50 +++++++++++++++++++++++++++++++ 3 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 dlls/kernelbase/tests/registry.c 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; diff --git a/dlls/kernelbase/tests/Makefile.in b/dlls/kernelbase/tests/Makefile.in index fe7ab212e6..99b7835896 100644 --- a/dlls/kernelbase/tests/Makefile.in +++ b/dlls/kernelbase/tests/Makefile.in @@ -2,6 +2,7 @@ TESTDLL = kernelbase.dll C_SRCS = \ path.c \ + registry.c \ sync.c RC_SRCS = \ diff --git a/dlls/kernelbase/tests/registry.c b/dlls/kernelbase/tests/registry.c new file mode 100644 index 0000000000..10246fcdc5 --- /dev/null +++ b/dlls/kernelbase/tests/registry.c @@ -0,0 +1,50 @@ +/* + * Registry tests for kernelbase.dll + * + * Copyright 2020 Jefferson Carpenter + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA + */ + +#include +#include +#include + +LSTATUS (WINAPI *pRegOpenKeyExW)(HKEY,LPCWSTR,DWORD,REGSAM,PHKEY); +LSTATUS (WINAPI *pRegOpenKeyExA)(HKEY,LPCSTR,DWORD,REGSAM,PHKEY); + +static void test_RegOpenKeyEx(void) { + HKEY key; + LSTATUS ret; + + key = (HKEY)10; + ret = pRegOpenKeyExW(0, L"", 0, KEY_READ, &key); + ok(ret == ERROR_INVALID_HANDLE, "expect ret %#x, got %#x\n", ERROR_INVALID_HANDLE, ret); + ok(NULL == key, "expect key %p, got %p\n", NULL, key); + + key = (HKEY)10; + ret = pRegOpenKeyExA(0, "", 0, KEY_READ, &key); + ok(ret == ERROR_INVALID_HANDLE, "expect ret %#x, got %#x\n", ERROR_INVALID_HANDLE, ret); + ok((void*)10 == key, "expect key %p, got %p\n", (void*)10, key); +} + +START_TEST(registry) +{ + HMODULE hmod = LoadLibraryA("kernelbase.dll"); + pRegOpenKeyExW = (void *)GetProcAddress(hmod, "RegOpenKeyExW"); + pRegOpenKeyExA = (void *)GetProcAddress(hmod, "RegOpenKeyExA"); + + test_RegOpenKeyEx(); +} -- 2.23.0