Signed-off-by: Alex Henrie alexhenrie24@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
Signed-off-by: Alex Henrie alexhenrie24@gmail.com --- dlls/advapi32/service.c | 2 ++ 1 file changed, 2 insertions(+)
diff --git a/dlls/advapi32/service.c b/dlls/advapi32/service.c index 11f4da0716..2856c9c808 100644 --- a/dlls/advapi32/service.c +++ b/dlls/advapi32/service.c @@ -1663,6 +1663,8 @@ BOOL WINAPI QueryServiceConfig2W(SC_HANDLE hService, DWORD dwLevel, LPBYTE buffe
if (!needed) { + if (dwLevel == SERVICE_CONFIG_DESCRIPTION) + heap_free(bufptr); SetLastError(ERROR_INVALID_ADDRESS); return FALSE; }
Alex Henrie alexhenrie24@gmail.com writes:
@@ -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;
You are also changing RegCreateKeyExW, but the tests only cover RegCreateKeyExA. It would be good to test both.