Commit 99748496 authored by Vincent Povirk's avatar Vincent Povirk Committed by Alexandre Julliard

advapi32: RegOpenKeyEx can return special roots when asked for empty subkey.

parent d8f79a03
...@@ -476,6 +476,14 @@ LSTATUS WINAPI RegOpenKeyExW( HKEY hkey, LPCWSTR name, DWORD options, REGSAM acc ...@@ -476,6 +476,14 @@ LSTATUS WINAPI RegOpenKeyExW( HKEY hkey, LPCWSTR name, DWORD options, REGSAM acc
OBJECT_ATTRIBUTES attr; OBJECT_ATTRIBUTES attr;
UNICODE_STRING nameW; UNICODE_STRING nameW;
if (retkey && (!name || !name[0]) &&
(HandleToUlong(hkey) >= HandleToUlong(HKEY_SPECIAL_ROOT_FIRST)) &&
(HandleToUlong(hkey) <= HandleToUlong(HKEY_SPECIAL_ROOT_LAST)))
{
*retkey = hkey;
return ERROR_SUCCESS;
}
/* NT+ allows beginning backslash for HKEY_CLASSES_ROOT */ /* NT+ allows beginning backslash for HKEY_CLASSES_ROOT */
if (HandleToUlong(hkey) == HandleToUlong(HKEY_CLASSES_ROOT) && name && *name == '\\') name++; if (HandleToUlong(hkey) == HandleToUlong(HKEY_CLASSES_ROOT) && name && *name == '\\') name++;
...@@ -520,6 +528,14 @@ LSTATUS WINAPI RegOpenKeyExA( HKEY hkey, LPCSTR name, DWORD options, REGSAM acce ...@@ -520,6 +528,14 @@ LSTATUS WINAPI RegOpenKeyExA( HKEY hkey, LPCSTR name, DWORD options, REGSAM acce
STRING nameA; STRING nameA;
NTSTATUS status; NTSTATUS status;
if (retkey && (!name || !name[0]) &&
(HandleToUlong(hkey) >= HandleToUlong(HKEY_SPECIAL_ROOT_FIRST)) &&
(HandleToUlong(hkey) <= HandleToUlong(HKEY_SPECIAL_ROOT_LAST)))
{
*retkey = hkey;
return ERROR_SUCCESS;
}
if (!is_version_nt()) access = MAXIMUM_ALLOWED; /* Win95 ignores the access mask */ if (!is_version_nt()) access = MAXIMUM_ALLOWED; /* Win95 ignores the access mask */
else else
{ {
......
...@@ -1075,7 +1075,6 @@ static void test_reg_open_key(void) ...@@ -1075,7 +1075,6 @@ static void test_reg_open_key(void)
ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */ ok(ret == ERROR_INVALID_HANDLE || ret == ERROR_BADKEY, /* Windows 95 returns BADKEY */
"expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret); "expected ERROR_INVALID_HANDLE or ERROR_BADKEY, got %d\n", ret);
ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n"); ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
RegCloseKey(hkResult);
/* send in NULL hkResult */ /* send in NULL hkResult */
ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL); ret = RegOpenKeyA(HKEY_CURRENT_USER, "Software\\Wine\\Test", NULL);
...@@ -1101,6 +1100,45 @@ static void test_reg_open_key(void) ...@@ -1101,6 +1100,45 @@ static void test_reg_open_key(void)
"expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret); "expected ERROR_SUCCESS, ERROR_BAD_PATHNAME or ERROR_FILE_NOT_FOUND, got %d\n", ret);
RegCloseKey(hkResult); RegCloseKey(hkResult);
/* NULL or empty subkey of special root */
hkResult = NULL;
ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, NULL, 0, KEY_QUERY_VALUE, &hkResult);
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
ok(hkResult == HKEY_CLASSES_ROOT, "expected hkResult == HKEY_CLASSES_ROOT\n");
hkResult = NULL;
ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "", 0, KEY_QUERY_VALUE, &hkResult);
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
ok(hkResult == HKEY_CLASSES_ROOT, "expected hkResult == HKEY_CLASSES_ROOT\n");
hkResult = NULL;
ret = RegOpenKeyExA(HKEY_CLASSES_ROOT, "\\", 0, KEY_QUERY_VALUE, &hkResult);
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
ok(hkResult != HKEY_CLASSES_ROOT, "expected hkResult to be a new key\n");
ok(!RegCloseKey(hkResult), "got invalid hkey\n");
/* empty subkey of existing handle */
hkResult = hkPreserve;
ret = RegOpenKeyExA(hkPreserve, "", 0, KEY_QUERY_VALUE, &hkResult);
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
ok(hkResult != hkPreserve, "expected hkResult != hkPreserve\n");
ok(!RegCloseKey(hkResult), "got invalid hkey\n");
/* NULL subkey of existing handle */
hkResult = hkPreserve;
ret = RegOpenKeyExA(hkPreserve, NULL, 0, KEY_QUERY_VALUE, &hkResult);
ok(ret == ERROR_SUCCESS, "expected ERROR_SUCCESS, got %d\n", ret);
ok(hkResult != hkPreserve, "expected hkResult != hkPreserve\n");
ok(!RegCloseKey(hkResult), "got invalid hkey\n");
/* empty subkey of NULL */
hkResult = hkPreserve;
ret = RegOpenKeyExA(NULL, "", 0, KEY_QUERY_VALUE, &hkResult);
ok(ret == ERROR_INVALID_HANDLE, "expected ERROR_INVALID_HANDLE, got %d\n", ret);
ok(hkResult == hkPreserve, "expected hkResult == hkPreserve\n");
RegCloseKey(hkPreserve);
/* WOW64 flags */ /* WOW64 flags */
hkResult = NULL; hkResult = NULL;
ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_32KEY, &hkResult); ret = RegOpenKeyExA(HKEY_LOCAL_MACHINE, "Software", 0, KEY_READ|KEY_WOW64_32KEY, &hkResult);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment