Skip to content

Commit

Permalink
[SHELL32] Stop SHELL_execute from always executing files (reactos#4363)
Browse files Browse the repository at this point in the history
CORE-18038
Add a check (PathIsExeW) to SHELL_execute to prevent it from executing non-exe files.
  • Loading branch information
AlexMiccolis authored Feb 15, 2022
1 parent d64ab28 commit 9b71653
Showing 1 changed file with 31 additions and 24 deletions.
55 changes: 31 additions & 24 deletions dll/win32/shell32/shlexec.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@

WINE_DEFAULT_DEBUG_CHANNEL(exec);

EXTERN_C BOOL PathIsExeW(LPCWSTR lpszPath);

#define SEE_MASK_CLASSALL (SEE_MASK_CLASSNAME | SEE_MASK_CLASSKEY)

typedef UINT_PTR (*SHELL_ExecuteW32)(const WCHAR *lpCmd, WCHAR *env, BOOL shWait,
Expand Down Expand Up @@ -2139,32 +2141,37 @@ static BOOL SHELL_execute(LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
lpFile = sei_tmp.lpFile;

wcmd = wcmdBuffer;
len = lstrlenW(wszApplicationName) + 3;
if (sei_tmp.lpParameters[0])
len += 1 + lstrlenW(wszParameters);
if (len > wcmdLen)
{
wcmd = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
wcmdLen = len;
}
swprintf(wcmd, L"\"%s\"", wszApplicationName);
if (sei_tmp.lpParameters[0])
{
strcatW(wcmd, L" ");
strcatW(wcmd, wszParameters);
}

retval = execfunc(wcmd, NULL, FALSE, &sei_tmp, sei);
if (retval > 32)
/* Only execute if it has an executable extension */
if (PathIsExeW(lpFile))
{
HeapFree(GetProcessHeap(), 0, wszApplicationName);
if (wszParameters != parametersBuffer)
HeapFree(GetProcessHeap(), 0, wszParameters);
if (wszDir != dirBuffer)
HeapFree(GetProcessHeap(), 0, wszDir);
if (wcmd != wcmdBuffer)
HeapFree(GetProcessHeap(), 0, wcmd);
return TRUE;
len = lstrlenW(wszApplicationName) + 3;
if (sei_tmp.lpParameters[0])
len += 1 + lstrlenW(wszParameters);
if (len > wcmdLen)
{
wcmd = (LPWSTR)HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
wcmdLen = len;
}
swprintf(wcmd, L"\"%s\"", wszApplicationName);
if (sei_tmp.lpParameters[0])
{
strcatW(wcmd, L" ");
strcatW(wcmd, wszParameters);
}

retval = execfunc(wcmd, NULL, FALSE, &sei_tmp, sei);
if (retval > 32)
{
HeapFree(GetProcessHeap(), 0, wszApplicationName);
if (wszParameters != parametersBuffer)
HeapFree(GetProcessHeap(), 0, wszParameters);
if (wszDir != dirBuffer)
HeapFree(GetProcessHeap(), 0, wszDir);
if (wcmd != wcmdBuffer)
HeapFree(GetProcessHeap(), 0, wcmd);
return TRUE;
}
}

/* Else, try to find the executable */
Expand Down

0 comments on commit 9b71653

Please sign in to comment.