[SHELL32] shlexec: Simplify parameters parsing (#7207)

Simplify code logic.
JIRA issue: N/A
- Use PathGetArgsW, PathRemoveArgsW,
  and PathUnquoteSpacesW for
  parsing parameters.
This commit is contained in:
Katayama Hirofumi MZ 2024-08-03 15:46:24 +09:00 committed by GitHub
parent deccfb8c9f
commit 266e2e5052
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -2153,39 +2153,26 @@ static BOOL SHELL_execute(LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
TRACE("execute: %s,%s,%s\n", debugstr_w(wszApplicationName), debugstr_w(wszParameters), debugstr_w(wszDir)); TRACE("execute: %s,%s,%s\n", debugstr_w(wszApplicationName), debugstr_w(wszParameters), debugstr_w(wszDir));
/* separate out command line arguments from executable file name */ /* separate out command line arguments from executable file name */
LPCWSTR lpFile; LPCWSTR lpFile = sei_tmp.lpFile;
WCHAR wfileName[MAX_PATH];
if (!*sei_tmp.lpParameters && !appKnownSingular) if (!*sei_tmp.lpParameters && !appKnownSingular)
{ {
/* If the executable path is quoted, handle the rest of the command line as parameters. */ /* If the executable path is quoted, handle the rest of the command line as parameters. */
if (sei_tmp.lpFile[0] == L'"') if (sei_tmp.lpFile[0] == L'"')
{ {
LPWSTR src = wszApplicationName/*sei_tmp.lpFile*/ + 1; LPWSTR pszArgs = PathGetArgsW(wszApplicationName);
LPWSTR dst = wfileName; PathRemoveArgsW(wszApplicationName);
LPWSTR end; PathUnquoteSpacesW(wszApplicationName);
parametersLen = lstrlenW(pszArgs);
/* copy the unquoted executable path to 'wfileName' */ if (parametersLen < _countof(parametersBuffer))
while(*src && *src != L'"')
*dst++ = *src++;
*dst = L'\0';
if (*src == L'"')
{ {
end = ++src; StringCchCopyW(parametersBuffer, _countof(parametersBuffer), pszArgs);
wszParameters = parametersBuffer;
while(isspaceW(*src))
++src;
} }
else else
end = src; {
wszParamAlloc.Attach(StrDupW(pszArgs));
/* copy the parameter string to 'wszParameters' */ wszParameters = wszParamAlloc;
strcpyW(wszParameters, src); }
/* terminate previous command string after the quote character */
*end = L'\0';
lpFile = wfileName;
} }
/* We have to test sei instead of sei_tmp because sei_tmp had its /* We have to test sei instead of sei_tmp because sei_tmp had its
* input fMask modified above in SHELL_translate_idlist. * input fMask modified above in SHELL_translate_idlist.
@ -2218,15 +2205,8 @@ static BOOL SHELL_execute(LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
break; break;
} }
} }
lpFile = sei_tmp.lpFile;
}
else
{
lpFile = sei_tmp.lpFile;
} }
} }
else
lpFile = sei_tmp.lpFile;
WCHAR wcmdBuffer[1024]; WCHAR wcmdBuffer[1024];
LPWSTR wcmd = wcmdBuffer; LPWSTR wcmd = wcmdBuffer;