https://git.reactos.org/?p=reactos.git;a=commitdiff;h=1ade494a70757b32202f13b50c86160fd3b56280

commit 1ade494a70757b32202f13b50c86160fd3b56280
Author:     Eric Kohl <[email protected]>
AuthorDate: Thu Oct 21 14:45:56 2021 +0200
Commit:     Eric Kohl <[email protected]>
CommitDate: Thu Oct 21 14:45:56 2021 +0200

    [ADVAPI32] Fix several corner cases in RegOpenKey* functions
    
    This fixes the remaining RegOpenKey* tests.
---
 dll/win32/advapi32/reg/reg.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/dll/win32/advapi32/reg/reg.c b/dll/win32/advapi32/reg/reg.c
index 3d739fb9d4f..9beecc99d2c 100644
--- a/dll/win32/advapi32/reg/reg.c
+++ b/dll/win32/advapi32/reg/reg.c
@@ -3264,12 +3264,7 @@ RegOpenKeyA(HKEY hKey,
     if (!phkResult)
         return ERROR_INVALID_PARAMETER;
 
-    if (!hKey && lpSubKey && phkResult)
-    {
-        return ERROR_INVALID_HANDLE;
-    }
-
-    if (!lpSubKey || !*lpSubKey)
+    if (!hKey && !lpSubKey)
     {
         *phkResult = hKey;
         return ERROR_SUCCESS;
@@ -3303,12 +3298,7 @@ RegOpenKeyW(HKEY hKey,
     if (!phkResult)
         return ERROR_INVALID_PARAMETER;
 
-    if (!hKey && lpSubKey && phkResult)
-    {
-        return ERROR_INVALID_HANDLE;
-    }
-
-    if (!lpSubKey || !*lpSubKey)
+    if (!hKey && !lpSubKey)
     {
         *phkResult = hKey;
         return ERROR_SUCCESS;
@@ -3383,6 +3373,17 @@ RegOpenKeyExW(HKEY hKey,
         return ERROR_INVALID_PARAMETER;
     }
 
+    if (!hKey && lpSubKey && phkResult)
+    {
+        return ERROR_INVALID_HANDLE;
+    }
+
+    if (IsPredefKey(hKey) && (!lpSubKey || !*lpSubKey))
+    {
+        *phkResult = hKey;
+        return ERROR_SUCCESS;
+    }
+
     Status = MapDefaultKey(&KeyHandle, hKey);
     if (!NT_SUCCESS(Status))
     {
@@ -3399,7 +3400,10 @@ RegOpenKeyExW(HKEY hKey,
     if (ulOptions & REG_OPTION_OPEN_LINK)
         Attributes |= OBJ_OPENLINK;
 
-    RtlInitUnicodeString(&SubKeyString, lpSubKey ? lpSubKey : L"");
+    if (lpSubKey == NULL || wcscmp(lpSubKey, L"\\") == 0)
+        RtlInitUnicodeString(&SubKeyString, L"");
+    else
+        RtlInitUnicodeString(&SubKeyString, lpSubKey);
 
     InitializeObjectAttributes(&ObjectAttributes,
                                &SubKeyString,

Reply via email to