From: Bruno Jesus <00cpxxx@gmail.com> Subject: shlwapi: Resist NULL key on SHRegCloseUSKey with tests Message-Id: Date: Sun, 6 Sep 2015 08:34:12 +0800 Fixes https://bugs.winehq.org/show_bug.cgi?id=36060 Fixes https://bugs.winehq.org/show_bug.cgi?id=36060
diff --git a/dlls/shlwapi/reg.c b/dlls/shlwapi/reg.c index 1653b80..a72f4c2 100644 --- a/dlls/shlwapi/reg.c +++ b/dlls/shlwapi/reg.c @@ -193,6 +193,9 @@ LONG WINAPI SHRegCloseUSKey( LPSHUSKEY hKey = hUSKey; LONG ret = ERROR_SUCCESS; + if (!hKey) + return ERROR_INVALID_PARAMETER; + if (hKey->HKCUkey) ret = RegCloseKey(hKey->HKCUkey); if (hKey->HKCUstart && hKey->HKCUstart != HKEY_CURRENT_USER) diff --git a/dlls/shlwapi/tests/shreg.c b/dlls/shlwapi/tests/shreg.c index dfc8c3e..ca7fbad 100644 --- a/dlls/shlwapi/tests/shreg.c +++ b/dlls/shlwapi/tests/shreg.c @@ -38,6 +38,8 @@ static DWORD (WINAPI *pSHCopyKeyA)(HKEY,LPCSTR,HKEY,DWORD); static DWORD (WINAPI *pSHRegGetPathA)(HKEY,LPCSTR,LPCSTR,LPSTR,DWORD); static LSTATUS (WINAPI *pSHRegGetValueA)(HKEY,LPCSTR,LPCSTR,SRRF,LPDWORD,LPVOID,LPDWORD); static LSTATUS (WINAPI *pSHRegCreateUSKeyW)(LPCWSTR,REGSAM,HUSKEY,PHUSKEY,DWORD); +static LSTATUS (WINAPI *pSHRegOpenUSKeyW)(LPCWSTR,REGSAM,HUSKEY,PHUSKEY,BOOL); +static LSTATUS (WINAPI *pSHRegCloseUSKey)(HUSKEY); static const char sTestpath1[] = "%LONGSYSTEMVAR%\\subdir1"; static const char sTestpath2[] = "%FOO%\\subdir1"; @@ -458,6 +460,35 @@ static void test_SHRegCreateUSKeyW(void) ok(ret == ERROR_INVALID_PARAMETER, "got %d\n", ret); } +static void test_SHRegCloseUSKey(void) +{ + static const WCHAR localW[] = {'S','o','f','t','w','a','r','e',0}; + LONG ret; + HUSKEY key; + + if (!pSHRegOpenUSKeyW || !pSHRegCloseUSKey) + { + win_skip("SHRegOpenUSKeyW or SHRegCloseUSKey not available\n"); + return; + } + + ret = pSHRegCloseUSKey(NULL); + ok(ret == ERROR_INVALID_PARAMETER, "got %d\n", ret); + + ret = pSHRegOpenUSKeyW(localW, KEY_ALL_ACCESS, NULL, &key, FALSE); + ok(ret == ERROR_SUCCESS, "got %d\n", ret); + + ret = pSHRegCloseUSKey(key); + ok(ret == ERROR_SUCCESS, "got %d\n", ret); + + /* Test with limited rights, specially without KEY_SET_VALUE */ + ret = pSHRegOpenUSKeyW(localW, KEY_QUERY_VALUE, NULL, &key, FALSE); + ok(ret == ERROR_SUCCESS, "got %d\n", ret); + + ret = pSHRegCloseUSKey(key); + ok(ret == ERROR_SUCCESS, "got %d\n", ret); +} + START_TEST(shreg) { HKEY hkey = create_test_entries(); @@ -476,6 +507,8 @@ START_TEST(shreg) pSHRegGetPathA = (void*)GetProcAddress(hshlwapi,"SHRegGetPathA"); pSHRegGetValueA = (void*)GetProcAddress(hshlwapi,"SHRegGetValueA"); pSHRegCreateUSKeyW = (void*)GetProcAddress(hshlwapi, "SHRegCreateUSKeyW"); + pSHRegOpenUSKeyW = (void*)GetProcAddress(hshlwapi, "SHRegOpenUSKeyW"); + pSHRegCloseUSKey = (void*)GetProcAddress(hshlwapi, "SHRegCloseUSKey"); test_SHGetValue(); test_SHRegGetValue(); @@ -484,6 +517,7 @@ START_TEST(shreg) test_SHCopyKey(); test_SHDeleteKey(); test_SHRegCreateUSKeyW(); + test_SHRegCloseUSKey(); delete_key( hkey, "Software\\Wine", "Test" ); }