mirror of
https://github.com/reactos/reactos.git
synced 2025-04-25 16:10:29 +00:00
- Fix obvious bugs in the code (e.g. freeing a stack-allocated pointer).
- Rewrite the code to be more readable. - Enlarge static buffer for SearchPathBuffer to be at least 5*MAX_PATH to prevent possible overflowing for now. In the meanwhile, Dmitry is rewriting this part of code to dynamically allocate the memory without the need for a temporary static storage. svn path=/trunk/; revision=40936
This commit is contained in:
parent
3c69a5f48e
commit
18c654d60a
1 changed files with 42 additions and 42 deletions
|
@ -185,19 +185,21 @@ LdrpQueryAppPaths(IN PCWSTR ImageName)
|
||||||
{
|
{
|
||||||
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
|
PKEY_VALUE_PARTIAL_INFORMATION KeyInfo;
|
||||||
OBJECT_ATTRIBUTES ObjectAttributes;
|
OBJECT_ATTRIBUTES ObjectAttributes;
|
||||||
WCHAR SearchPathBuffer[MAX_PATH];
|
WCHAR SearchPathBuffer[5*MAX_PATH];
|
||||||
UNICODE_STRING ValueNameString;
|
UNICODE_STRING ValueNameString;
|
||||||
UNICODE_STRING KeyName;
|
UNICODE_STRING KeyName;
|
||||||
WCHAR NameBuffer[256];
|
WCHAR NameBuffer[MAX_PATH];
|
||||||
ULONG KeyInfoSize;
|
ULONG KeyInfoSize;
|
||||||
ULONG ResultSize;
|
ULONG ResultSize;
|
||||||
ULONG len;
|
PWCHAR Backslash;
|
||||||
HANDLE KeyHandle;
|
HANDLE KeyHandle;
|
||||||
NTSTATUS Status;
|
NTSTATUS Status;
|
||||||
PWSTR Path = NULL;
|
PWSTR Path = NULL;
|
||||||
|
|
||||||
swprintf(NameBuffer,
|
_snwprintf(NameBuffer,
|
||||||
L"\\Registry\\Machine\\Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s", ImageName);
|
sizeof(NameBuffer) / sizeof(WCHAR),
|
||||||
|
L"\\Registry\\Machine\\Software\\Microsoft\\Windows\\CurrentVersion\\App Paths\\%s",
|
||||||
|
ImageName);
|
||||||
|
|
||||||
RtlInitUnicodeString(&KeyName, NameBuffer);
|
RtlInitUnicodeString(&KeyName, NameBuffer);
|
||||||
|
|
||||||
|
@ -236,49 +238,47 @@ LdrpQueryAppPaths(IN PCWSTR ImageName)
|
||||||
KeyInfoSize,
|
KeyInfoSize,
|
||||||
&ResultSize);
|
&ResultSize);
|
||||||
|
|
||||||
if (NT_SUCCESS(Status))
|
if (!NT_SUCCESS(Status))
|
||||||
{
|
return NULL;
|
||||||
RtlCopyMemory(SearchPathBuffer,
|
|
||||||
&KeyInfo->Data,
|
|
||||||
KeyInfo->DataLength);
|
|
||||||
|
|
||||||
/* get application running path */
|
RtlCopyMemory(SearchPathBuffer,
|
||||||
wcscat(SearchPathBuffer, L";");
|
&KeyInfo->Data,
|
||||||
wcscat (SearchPathBuffer, NtCurrentPeb()->ProcessParameters->ImagePathName.Buffer);
|
KeyInfo->DataLength);
|
||||||
|
|
||||||
len = wcslen (SearchPathBuffer);
|
|
||||||
|
|
||||||
while (len && SearchPathBuffer[len - 1] != L'\\')
|
|
||||||
len--;
|
|
||||||
|
|
||||||
if (len) SearchPathBuffer[len-1] = L'\0';
|
|
||||||
|
|
||||||
wcscat (SearchPathBuffer, L";");
|
|
||||||
|
|
||||||
wcscat (SearchPathBuffer, SharedUserData->NtSystemRoot);
|
|
||||||
wcscat (SearchPathBuffer, L"\\system32;");
|
|
||||||
wcscat (SearchPathBuffer, SharedUserData->NtSystemRoot);
|
|
||||||
wcscat (SearchPathBuffer, L";.");
|
|
||||||
|
|
||||||
Path = RtlAllocateHeap(RtlGetProcessHeap(),
|
|
||||||
0,
|
|
||||||
wcslen(SearchPathBuffer) * sizeof(WCHAR));
|
|
||||||
|
|
||||||
if (Path == NULL)
|
|
||||||
{
|
|
||||||
DPRINT("RtlAllocateHeap() failed\n");
|
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
|
||||||
NtClose(KeyHandle);
|
|
||||||
return NULL;
|
|
||||||
}
|
|
||||||
|
|
||||||
Path = SearchPathBuffer;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/* Free KeyInfo memory, we won't need it anymore */
|
||||||
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
RtlFreeHeap(RtlGetProcessHeap(), 0, KeyInfo);
|
||||||
|
|
||||||
|
/* Close the key handle */
|
||||||
NtClose(KeyHandle);
|
NtClose(KeyHandle);
|
||||||
|
|
||||||
|
/* get application running path */
|
||||||
|
wcscat(SearchPathBuffer, L";");
|
||||||
|
wcscat(SearchPathBuffer, NtCurrentPeb()->ProcessParameters->ImagePathName.Buffer); // FIXME: Don't rely on it being NULL-terminated!!!
|
||||||
|
|
||||||
|
/* Remove trailing backslash */
|
||||||
|
Backslash = wcsrchr(SearchPathBuffer, L'\\');
|
||||||
|
if (Backslash) Backslash = L'\0';
|
||||||
|
|
||||||
|
wcscat(SearchPathBuffer, L";");
|
||||||
|
|
||||||
|
wcscat(SearchPathBuffer, SharedUserData->NtSystemRoot);
|
||||||
|
wcscat(SearchPathBuffer, L"\\system32;");
|
||||||
|
wcscat(SearchPathBuffer, SharedUserData->NtSystemRoot);
|
||||||
|
wcscat(SearchPathBuffer, L";.");
|
||||||
|
|
||||||
|
/* Copy it to the heap allocd memory */
|
||||||
|
Path = RtlAllocateHeap(RtlGetProcessHeap(),
|
||||||
|
0,
|
||||||
|
wcslen(SearchPathBuffer) * sizeof(WCHAR));
|
||||||
|
|
||||||
|
if (!Path)
|
||||||
|
{
|
||||||
|
DPRINT1("RtlAllocateHeap() failed\n");
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
wcscpy(Path, SearchPathBuffer);
|
||||||
|
|
||||||
return Path;
|
return Path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue