[NTOS:CM] Simplify CmpGetRegistryPath to avoid unnecessary stack buffers. CORE-15882

This commit is contained in:
Thomas Faber
2019-04-17 10:25:52 +02:00
parent d570482bc7
commit 047a3bf79a

View 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);