[PATCH v2 1/2] advapi32: Return ERROR_BADKEY from RegCreateKeyEx[AW] when appropriate

Alex Henrie alexhenrie24 at gmail.com
Tue Nov 6 22:11:53 CST 2018


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

diff --git a/dlls/advapi32/registry.c b/dlls/advapi32/registry.c
index 9989097ff4..0a8ccfbf20 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 || !retkey) 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 || !retkey) 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..ed14ae92b4 100644
--- a/dlls/advapi32/tests/registry.c
+++ b/dlls/advapi32/tests/registry.c
@@ -1297,6 +1297,30 @@ static void test_reg_create_key(void)
     PACL key_acl;
     SECURITY_DESCRIPTOR *sd;
 
+    ret = RegCreateKeyExA(INVALID_HANDLE_VALUE, NULL, 1, NULL, 0, 0, NULL, NULL, NULL);
+    ok(ret == ERROR_INVALID_PARAMETER, "RegCreateKeyExA returned %d\n", ret);
+
+    ret = RegCreateKeyExA(INVALID_HANDLE_VALUE, NULL, 0, NULL, 0, 0, NULL, NULL, NULL);
+    ok(ret == ERROR_BADKEY, "RegCreateKeyExA returned %d\n", ret);
+
+    ret = RegCreateKeyExA(INVALID_HANDLE_VALUE, NULL, 0, NULL, 0, 0, NULL, (HKEY *)0xdeadbeef, NULL);
+    ok(ret == ERROR_BADKEY, "RegCreateKeyExA returned %d\n", ret);
+
+    ret = RegCreateKeyExA(INVALID_HANDLE_VALUE, (const char *)0xdeadbeef, 0, NULL, 0, 0, NULL, NULL, NULL);
+    ok(ret == ERROR_BADKEY, "RegCreateKeyExA returned %d\n", ret);
+
+    ret = RegCreateKeyExW(INVALID_HANDLE_VALUE, NULL, 1, NULL, 0, 0, NULL, NULL, NULL);
+    ok(ret == ERROR_INVALID_PARAMETER, "RegCreateKeyExA returned %d\n", ret);
+
+    ret = RegCreateKeyExW(INVALID_HANDLE_VALUE, NULL, 0, NULL, 0, 0, NULL, NULL, NULL);
+    ok(ret == ERROR_BADKEY, "RegCreateKeyExA returned %d\n", ret);
+
+    ret = RegCreateKeyExW(INVALID_HANDLE_VALUE, NULL, 0, NULL, 0, 0, NULL, (HKEY *)0xdeadbeef, NULL);
+    ok(ret == ERROR_BADKEY, "RegCreateKeyExA returned %d\n", ret);
+
+    ret = RegCreateKeyExW(INVALID_HANDLE_VALUE, (const WCHAR *)0xdeadbeef, 0, NULL, 0, 0, NULL, NULL, NULL);
+    ok(ret == ERROR_BADKEY, "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