advapi32: RegEnumKeyEx() should return "ERROR_INVALID_PARAMETER" if name_len is NULL (Try 2)

Andrew Talbot andrew.talbot at talbotville.com
Mon Jun 2 17:35:14 CDT 2008


This time with test.

-- Andy.
---
Changelog:
    advapi32: RegEnumKeyEx() should return "ERROR_INVALID_PARAMETER" if name_len is NULL.

diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index 9ce3da0..41ef3bf 100644
--- a/dlls/advapi32/registry.c
+++ b/dlls/advapi32/registry.c
@@ -473,7 +473,7 @@ LSTATUS WINAPI RegEnumKeyExW( HKEY hkey, DWORD index, LPWSTR name, LPDWORD name_
     TRACE( "(%p,%d,%p,%p(%d),%p,%p,%p,%p)\n", hkey, index, name, name_len,
            name_len ? *name_len : -1, reserved, class, class_len, ft );
 
-    if (reserved) return ERROR_INVALID_PARAMETER;
+    if (!name_len || reserved) return ERROR_INVALID_PARAMETER;
     if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
 
     status = NtEnumerateKey( hkey, index, KeyNodeInformation,
@@ -537,7 +537,7 @@ LSTATUS WINAPI RegEnumKeyExA( HKEY hkey, DWORD index, LPSTR name, LPDWORD name_l
     TRACE( "(%p,%d,%p,%p(%d),%p,%p,%p,%p)\n", hkey, index, name, name_len,
            name_len ? *name_len : -1, reserved, class, class_len, ft );
 
-    if (reserved) return ERROR_INVALID_PARAMETER;
+    if (!name_len || reserved) return ERROR_INVALID_PARAMETER;
     if (!(hkey = get_special_root_hkey( hkey ))) return ERROR_INVALID_HANDLE;
 
     status = NtEnumerateKey( hkey, index, KeyNodeInformation,
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index fe3d3ff..72ab447 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -854,7 +854,42 @@ static void test_get_value(void)
     /* Query REG_EXPAND_SZ using RRF_RT_REG_EXPAND_SZ (not allowed without RRF_NOEXPAND) */
     ret = pRegGetValueA(hkey_main, NULL, "TP1_EXP_SZ", RRF_RT_REG_EXPAND_SZ, NULL, NULL, NULL);
     ok(ret == ERROR_INVALID_PARAMETER, "ret=%d\n", ret);
-} 
+}
+
+static void test_enum_key(void)
+{
+    DWORD ret;
+
+    static WCHAR subkey1W[] = {'S','u','b','k','e','y','1',0};
+
+    static CHAR subkey1A[] = "Subkey1";
+
+    HKEY hkey1;
+    DWORD idx;
+    LPDWORD subkey1A_len, subkey1W_len;
+
+    ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_ENUMERATE_SUB_KEYS, NULL, &hkey1, NULL);
+    ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
+
+    /* ANSI tests */
+
+    /* enumerate one subkey with name_len set to NULL */
+    idx = 0;
+    subkey1A_len = NULL;
+    ret = RegEnumKeyExA( hkey_main, idx, subkey1A, subkey1A_len, NULL, NULL, NULL, NULL );
+    ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
+
+    /* UNICODE tests */
+
+    /* enumerate one subkey with name_len set to NULL */
+    idx = 0;
+    subkey1W_len = NULL;
+    ret = RegEnumKeyExW( hkey_main, idx, subkey1W, subkey1W_len, NULL, NULL, NULL, NULL );
+    ok(ret == ERROR_INVALID_PARAMETER, "Expected ERROR_INVALID_PARAMETER, got %d\n", ret);
+
+    RegDeleteKeyA(hkey1, "");
+    RegCloseKey(hkey1);
+}
 
 static void test_reg_open_key(void)
 {
@@ -1344,6 +1379,7 @@ START_TEST(registry)
     test_enum_value();
     test_query_value_ex();
     test_get_value();
+    test_enum_key();
     test_reg_open_key();
     test_reg_create_key();
     test_reg_close_key();



More information about the wine-patches mailing list