[PATCH] advapi32: Return error from RegCreateKeyEx[AW] if the key name is null

Alex Henrie alexhenrie24 at gmail.com
Sun Nov 4 15:15:23 CST 2018


Signed-off-by: Alex Henrie <alexhenrie24 at gmail.com>
---
Fixes Coverity #731771
---
 dlls/advapi32/registry.c       | 4 +++-
 dlls/advapi32/tests/registry.c | 9 +++++++++
 2 files changed, 12 insertions(+), 1 deletion(-)

diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index 9989097ff4..0601e43d3c 100644
--- a/dlls/advapi32/registry.c
+++ b/dlls/advapi32/registry.c
@@ -371,6 +371,7 @@ LSTATUS WINAPI RegCreateKeyExW( HKEY hkey, LPCWSTR name, DWORD reserved, LPWSTR
     UNICODE_STRING nameW, classW;
 
     if (reserved) return ERROR_INVALID_PARAMETER;
+    if (!name) return ERROR_BADKEY;
     if (!(hkey = get_special_root_hkey( hkey, access ))) return ERROR_INVALID_HANDLE;
 
     attr.Length = sizeof(attr);
@@ -420,10 +421,11 @@ LSTATUS WINAPI RegCreateKeyExA( HKEY hkey, LPCSTR name, DWORD reserved, LPSTR cl
     NTSTATUS status;
 
     if (reserved) return ERROR_INVALID_PARAMETER;
+    if (!name) return ERROR_BADKEY;
     if (!is_version_nt())
     {
         access = MAXIMUM_ALLOWED;  /* Win95 ignores the access mask */
-        if (name && *name == '\\') name++; /* win9x,ME ignores one (and only one) beginning backslash */
+        if (name[0] == '\\') name++; /* win9x,ME ignores one (and only one) beginning backslash */
     }
     if (!(hkey = get_special_root_hkey( hkey, access ))) return ERROR_INVALID_HANDLE;
 
diff --git a/dlls/advapi32/tests/registry.c b/dlls/advapi32/tests/registry.c
index 6043cab184..21698220aa 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -1297,6 +1297,15 @@ static void test_reg_create_key(void)
     PACL key_acl;
     SECURITY_DESCRIPTOR *sd;
 
+    ret = RegCreateKeyExA(INVALID_HANDLE_VALUE, NULL, 1, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
+    ok(ret == ERROR_INVALID_PARAMETER, "RegCreateKeyExA returned %d\n", ret);
+
+    ret = RegCreateKeyExA(INVALID_HANDLE_VALUE, NULL, 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
+    ok(ret == ERROR_BADKEY, "RegCreateKeyExA returned %d\n", ret);
+
+    ret = RegCreateKeyExA(INVALID_HANDLE_VALUE, "Subkey1", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
+    ok(ret == ERROR_INVALID_HANDLE, "RegCreateKeyExA returned %d\n", ret);
+
     ret = RegCreateKeyExA(hkey_main, "Subkey1", 0, NULL, 0, KEY_NOTIFY, NULL, &hkey1, NULL);
     ok(!ret, "RegCreateKeyExA failed with error %d\n", ret);
     /* should succeed: all versions of Windows ignore the access rights
-- 
2.19.1




More information about the wine-devel mailing list