Skip to content

Commit

Permalink
Improved cmdline parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
mxmauro committed Aug 21, 2022
1 parent 8fd14fc commit cb4b9f6
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 18 deletions.
38 changes: 21 additions & 17 deletions CrashReport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,28 +86,32 @@ BOOL HandleCrashDump(_In_z_ LPCWSTR szModuleNameW)
if (sW == NULL || *sW == 0)
return FALSE;

while (*sW != 0)
//skip spaces before
while (*sW != 0 && *((LPWORD)sW) <= 32)
sW++;

//inside quotes?
if (*sW == L'"')
{
if (*sW == L'"')
{
sW++;
//skip until the closing quotes
while (*sW != 0 && *sW != L'"')
sW++;
while (*sW != 0 && *sW != L'"')
sW++;
if (*sW == L'"')
sW++;
}
else if (*sW == L' ')
{
while (*sW != 0 && *sW <= 32)
sW++;
break;
}
else
{
if (*sW == L'"')
sW++; //skip the closing quote
}
else
{
//skip until the first blank space
while (*((LPWORD)sW) > 32)
sW++;
}
}

//skip spaces after
while (*sW != 0 && *((LPWORD)sW) <= 32)
sW++;

//check parameter
if (StrNCompareW(sW, L"/crash:", 7) != 0)
return FALSE; //not a crash handler
sW += 7;
Expand Down
4 changes: 3 additions & 1 deletion Process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ HRESULT ResolveChildProcessFileName(_Out_ CStringW &cStrFullNameW, _In_ LPCWSTR
LPCWSTR szNameStartW, szNameEndW;
SIZE_T nTempBufLen = 1024;

//NOTE: Assume szCommandLineW is the full command line
szNameStartW = szCommandLineW;
if (*szCommandLineW == L'"')
{
Expand All @@ -70,9 +71,10 @@ HRESULT ResolveChildProcessFileName(_Out_ CStringW &cStrFullNameW, _In_ LPCWSTR
else
{
szNameEndW = szNameStartW;
while (*szNameEndW != 0 && *szNameEndW != L' ' && *szNameEndW != L'\t')
while (*((LPWORD)szNameEndW) > 32)
szNameEndW++;
}

//get the path list to check (based on https://msdn.microsoft.com/en-us/library/ms682425.aspx)
//1. The directory from which the application loaded.
hRes = FileRoutines::GetAppFolderPath(cStrSearchPathW);
Expand Down

0 comments on commit cb4b9f6

Please sign in to comment.