Module: wine Branch: master Commit: ffb4d151174be47b728099e0d203474e5e6d1b5a URL: http://source.winehq.org/git/wine.git/?a=commit;h=ffb4d151174be47b728099e0d2...
Author: Bruno Jesus 00cpxxx@gmail.com Date: Sun Sep 6 08:34:12 2015 +0800
shlwapi: Reject NULL key on SHRegCloseUSKey with tests.
---
dlls/shlwapi/reg.c | 3 +++ dlls/shlwapi/tests/shreg.c | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 37 insertions(+)
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" ); }