Skip to content

Commit eb1a43d

Browse files
committed
[0.4.12][SHELL32] ShellExecute again, fix regression CORE-16299
We unintentionally introduced CORE-16299 by 0.4.12-RC-47-g 625a5a0 Thx to author Doug Lyons for this patch! Master is also affected, but will be serviced later.
1 parent d52cac4 commit eb1a43d

File tree

1 file changed

+47
-1
lines changed

1 file changed

+47
-1
lines changed

dll/win32/shell32/shlexec.cpp

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1993,7 +1993,53 @@ static BOOL SHELL_execute(LPSHELLEXECUTEINFOW sei, SHELL_ExecuteW32 execfunc)
19931993
}
19941994
else
19951995
{
1996-
lpFile = sei_tmp.lpFile;
1996+
/* If the executable name is not quoted, we have to use this search loop here,
1997+
that in CreateProcess() is not sufficient because it does not handle shell links. */
1998+
WCHAR buffer[MAX_PATH], xlpFile[MAX_PATH], lpFilesave[MAX_PATH];
1999+
WCHAR wszParamSave[MAX_PATH], wszAppNameSave[MAX_PATH];
2000+
LPWSTR space, s;
2001+
2002+
/* Save inputs in case we need to revert them later */
2003+
memcpy(lpFilesave, sei_tmp.lpFile, wcslen(sei_tmp.lpFile) * sizeof(WCHAR) + 2);
2004+
memcpy(wszParamSave, sei_tmp.lpParameters, wcslen(sei_tmp.lpParameters) * sizeof(WCHAR) + 2);
2005+
memcpy(wszAppNameSave, wszApplicationName, wcslen(wszApplicationName) * sizeof(WCHAR) + 2);
2006+
2007+
LPWSTR beg = wszApplicationName/*sei_tmp.lpFile*/;
2008+
for(s = beg; (space = const_cast<LPWSTR>(strchrW(s, L' '))); s = space + 1)
2009+
{
2010+
int idx = space - sei_tmp.lpFile;
2011+
memcpy(buffer, sei_tmp.lpFile, idx * sizeof(WCHAR));
2012+
buffer[idx] = '\0';
2013+
2014+
/*FIXME This finds directory paths if the targeted file name contains spaces. */
2015+
if (SearchPathW(*sei_tmp.lpDirectory ? sei_tmp.lpDirectory : NULL, buffer, wszExe, sizeof(xlpFile) / sizeof(xlpFile[0]), xlpFile, NULL))
2016+
{
2017+
/* separate out command from parameter string */
2018+
LPCWSTR p = space + 1;
2019+
2020+
while(isspaceW(*p))
2021+
++p;
2022+
2023+
strcpyW(wszParameters, p);
2024+
*space = L'\0';
2025+
2026+
break;
2027+
}
2028+
}
2029+
2030+
/* test if we end in '.exe' and if so keep changes.
2031+
Revert to beginning values if we do not. */
2032+
if (!wcsicmp(sei_tmp.lpFile + wcslen(sei_tmp.lpFile) - 4, wszExe))
2033+
{
2034+
lpFile = sei_tmp.lpFile;
2035+
}
2036+
else
2037+
{
2038+
lpFile = lpFilesave;
2039+
sei_tmp.lpFile = lpFilesave;
2040+
strcpyW(wszParameters, wszParamSave);
2041+
strcpyW(wszApplicationName, wszAppNameSave);
2042+
}
19972043
}
19982044
}
19992045
else

0 commit comments

Comments
 (0)