Make the default command line the quoted image path, to prevent empty command lines in case no arguments were specified

This commit is contained in:
Mattiwatti 2017-07-29 05:53:47 +02:00
parent ef7deb59d4
commit 86fe598475
No known key found for this signature in database
GPG Key ID: D40D1DBE299B83EA
1 changed files with 9 additions and 8 deletions

View File

@ -215,15 +215,16 @@ __declspec(dllexport) void* TITCALL InitNativeDebugW(wchar_t* szFileName, wchar_
goto finished; goto finished;
// Convert command line and directory to UNICODE_STRING if present // Convert command line and directory to UNICODE_STRING if present
SIZE_T ArgumentsLength = lstrlenW(szCommandLine); SIZE_T ArgumentsLength = szCommandLine != NULL ? lstrlenW(szCommandLine) : 0;
if(szCommandLine != NULL && ArgumentsLength > 0)
{
SIZE_T BufferSize = ImagePath.Length + ((ArgumentsLength + 4) * sizeof(wchar_t)); SIZE_T BufferSize = ImagePath.Length + ((ArgumentsLength + 4) * sizeof(wchar_t));
CommandLine.Buffer = (PWSTR)RtlAllocateHeap(RtlProcessHeap(), HEAP_ZERO_MEMORY, BufferSize); CommandLine.Buffer = (PWSTR)RtlAllocateHeap(RtlProcessHeap(), HEAP_ZERO_MEMORY, BufferSize * 10);
CommandLine.MaximumLength = (USHORT)BufferSize; CommandLine.MaximumLength = (USHORT)BufferSize;
RtlAppendUnicodeToString(&CommandLine, L"\""); RtlAppendUnicodeToString(&CommandLine, L"\"");
RtlAppendUnicodeStringToString(&CommandLine, &ImagePath); RtlAppendUnicodeStringToString(&CommandLine, &ImagePath);
RtlAppendUnicodeToString(&CommandLine, L"\" "); RtlAppendUnicodeToString(&CommandLine, L"\"");
if(ArgumentsLength > 0)
{
RtlAppendUnicodeToString(&CommandLine, L" ");
RtlAppendUnicodeToString(&CommandLine, szCommandLine); RtlAppendUnicodeToString(&CommandLine, szCommandLine);
} }