[EXPLORER] Allocate the string for expanded command line from heap

Addendum to 6fe704b.

CORE-12973 CORE-17168
This commit is contained in:
Stanislav Motylkov 2020-07-21 19:50:45 +03:00
parent 6fe704b0f0
commit 21b56d77c6
No known key found for this signature in database
GPG key ID: AFE513258CBA9E92

View file

@ -229,6 +229,7 @@ static BOOL ProcessRunKeys(HKEY hkRoot, LPCWSTR szKeyName, BOOL bDelete,
while (i > 0)
{
WCHAR *szCmdLineExp = NULL;
DWORD cchValLength = cchMaxValue, cbDataLength = cbMaxCmdLine;
DWORD type;
@ -266,18 +267,37 @@ static BOOL ProcessRunKeys(HKEY hkRoot, LPCWSTR szKeyName, BOOL bDelete,
if (type == REG_EXPAND_SZ)
{
WCHAR szCmdLineExp[MAX_PATH + 1] = L"\0";
DWORD dwNumOfChars;
if (ExpandEnvironmentStringsW(szCmdLine, szCmdLineExp, _countof(szCmdLineExp)))
StringCbCopyW(szCmdLine, cbMaxCmdLine, szCmdLineExp);
dwNumOfChars = ExpandEnvironmentStringsW(szCmdLine, NULL, 0);
if (dwNumOfChars)
{
szCmdLineExp = (WCHAR *)HeapAlloc(hProcessHeap, 0, dwNumOfChars * sizeof(*szCmdLineExp));
if (szCmdLineExp == NULL)
{
TRACE("Couldn't allocate memory for the commands to be executed\n");
res = ERROR_NOT_ENOUGH_MEMORY;
goto end;
}
ExpandEnvironmentStringsW(szCmdLine, szCmdLineExp, dwNumOfChars);
}
}
res = runCmd(szCmdLine, NULL, bSynchronous, FALSE);
res = runCmd(szCmdLineExp ? szCmdLineExp : szCmdLine, NULL, bSynchronous, FALSE);
if (res == INVALID_RUNCMD_RETURN)
{
TRACE("Error running cmd #%lu (%lu)\n", i, GetLastError());
}
if (szCmdLineExp != NULL)
{
HeapFree(hProcessHeap, 0, szCmdLineExp);
szCmdLineExp = NULL;
}
TRACE("Done processing cmd #%lu\n", i);
}