[NTOS:CM] Simplify CmpGetRegistryPath to avoid unnecessary stack buffers. CORE-15882
authorThomas Faber <thomas.faber@reactos.org>
Wed, 17 Apr 2019 08:25:52 +0000 (10:25 +0200)
committerThomas Faber <thomas.faber@reactos.org>
Sun, 5 May 2019 08:39:22 +0000 (10:39 +0200)
ntoskrnl/config/cmsysini.c

index d672ead..c773f1f 100644 (file)
@@ -1166,32 +1166,24 @@ CmpCreateRegistryRoot(VOID)
     return TRUE;
 }
 
-static NTSTATUS
-CmpGetRegistryPath(OUT PWCHAR ConfigPath)
+static PCWSTR
+CmpGetRegistryPath(VOID)
 {
-    /* Just use default path */
-    wcscpy(ConfigPath, L"\\SystemRoot");
+    PCWSTR ConfigPath;
 
     /* Check if we are booted in setup */
     if (!ExpInTextModeSetup)
     {
-        /* Add registry path */
-#if 0
-        ResultSize = wcslen(ConfigPath);
-        if (ResultSize && ConfigPath[ResultSize - 1] == L'\\')
-            ConfigPath[ResultSize - 1] = UNICODE_NULL;
-#endif
-        wcscat(ConfigPath, L"\\System32\\Config\\");
+        ConfigPath = L"\\SystemRoot\\System32\\Config\\";
     }
     else
     {
-        wcscat(ConfigPath, L"\\");
+        ConfigPath = L"\\SystemRoot\\";
     }
 
     DPRINT1("CmpGetRegistryPath: ConfigPath = '%S'\n", ConfigPath);
 
-    /* Done */
-    return STATUS_SUCCESS;
+    return ConfigPath;
 }
 
 _Function_class_(KSTART_ROUTINE)
@@ -1199,7 +1191,8 @@ VOID
 NTAPI
 CmpLoadHiveThread(IN PVOID StartContext)
 {
-    WCHAR FileBuffer[MAX_PATH], RegBuffer[MAX_PATH], ConfigPath[MAX_PATH];
+    WCHAR FileBuffer[MAX_PATH], RegBuffer[MAX_PATH];
+    PCWSTR ConfigPath;
     UNICODE_STRING TempName, FileName, RegName;
     ULONG i, ErrorResponse, WorkerCount, Length;
     USHORT FileStart;
@@ -1222,7 +1215,7 @@ CmpLoadHiveThread(IN PVOID StartContext)
     RtlInitEmptyUnicodeString(&RegName, RegBuffer, sizeof(RegBuffer));
 
     /* Now build the system root path */
-    CmpGetRegistryPath(ConfigPath);
+    ConfigPath = CmpGetRegistryPath();
     RtlInitUnicodeString(&TempName, ConfigPath);
     RtlAppendUnicodeStringToString(&FileName, &TempName);
     FileStart = FileName.Length;
@@ -1364,7 +1357,8 @@ VOID
 NTAPI
 CmpInitializeHiveList(VOID)
 {
-    WCHAR FileBuffer[MAX_PATH], RegBuffer[MAX_PATH], ConfigPath[MAX_PATH];
+    WCHAR FileBuffer[MAX_PATH], RegBuffer[MAX_PATH];
+    PCWSTR ConfigPath;
     UNICODE_STRING TempName, FileName, RegName;
     HANDLE Thread;
     NTSTATUS Status;
@@ -1381,7 +1375,7 @@ CmpInitializeHiveList(VOID)
     RtlInitEmptyUnicodeString(&RegName, RegBuffer, sizeof(RegBuffer));
 
     /* Now build the system root path */
-    CmpGetRegistryPath(ConfigPath);
+    ConfigPath = CmpGetRegistryPath();
     RtlInitUnicodeString(&TempName, ConfigPath);
     RtlAppendUnicodeStringToString(&FileName, &TempName);