[SHELL32] SHELL_FindExecutable: improve path handling code (#7633)

Follow-up of 42d5dfd3de.
- Revert "shell32: Fix ShellExecute for non-filespec paths." 0bad544aab.
- Apply "shell32: Look for the file name without extension also for the path search case." 38b6640be9.
- Clear leading/trailing whitespaces (an improvement by Doug Lyons).
- Update the comment for xlpFile buffer definition, to match the current code behaviour.
This fixes some failures for the following tests:
- shell32_apitest:ShellExecCmdLine: 12 failures less,
- shell32_apitest:ShellExecuteEx: 5 failures less,
- shell32_winetest:shlexec: crash fixed, now 13 failures as before,
- wshom_winetest:wshom: crash fixed, now 2 failures less too (0 failures).
I've also tested: the problem which was intended to be fixed by the guilty commit (CORE-19953) still remains fixed after this change.
CORE-19964
This commit is contained in:
Oleg Dubinskiy 2025-01-18 21:51:58 +01:00 committed by GitHub
parent fe7a58d92e
commit c7d1aa3e92
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -748,7 +748,7 @@ static UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpVerb,
WCHAR wBuffer[256]; /* Used to GetProfileString */
UINT retval = SE_ERR_NOASSOC;
WCHAR *tok; /* token pointer */
WCHAR xlpFile[MAX_PATH]; /* result of SearchPath */
WCHAR xlpFile[MAX_PATH]; /* result of PathResolve */
DWORD attribs; /* file attributes */
WCHAR curdir[MAX_PATH];
const WCHAR *search_paths[3] = {0};
@ -777,55 +777,29 @@ static UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpVerb,
}
GetCurrentDirectoryW(ARRAY_SIZE(curdir), curdir);
if (!PathIsFileSpecW(lpFile))
if (lpPath && *lpPath)
{
BOOL found = FALSE;
if (lpPath && *lpPath)
{
TRACE("lpPath %s\n", debugstr_w(lpPath));
PathCombineW(xlpFile, lpPath, lpFile);
if (PathFileExistsDefExtW(xlpFile, WHICH_DEFAULT | WHICH_OPTIONAL) || PathFileExistsW(xlpFile))
{
GetFullPathNameW(xlpFile, ARRAY_SIZE(xlpFile), xlpFile, NULL);
found = TRUE;
}
}
if (!found)
{
lstrcpyW(xlpFile, lpFile);
if (PathFileExistsDefExtW(xlpFile, WHICH_DEFAULT | WHICH_OPTIONAL) || PathFileExistsW(xlpFile))
{
GetFullPathNameW(xlpFile, ARRAY_SIZE(xlpFile), xlpFile, NULL);
found = TRUE;
}
}
if (found)
{
lpFile = xlpFile;
lstrcpyW(lpResult, xlpFile);
}
else
xlpFile[0] = '\0';
search_paths[0] = lpPath;
search_paths[1] = curdir;
}
else
{
if (lpPath && *lpPath)
{
search_paths[0] = lpPath;
search_paths[1] = curdir;
}
else
search_paths[0] = curdir;
lstrcpyW(xlpFile, lpFile);
if (PathResolveW(xlpFile, search_paths, PRF_TRYPROGRAMEXTENSIONS | PRF_VERIFYEXISTS))
{
TRACE("PathResolveW returned non-zero\n");
lpFile = xlpFile;
lstrcpyW(lpResult, xlpFile);
/* The file was found in lpPath or one of the directories in the system-wide search path */
}
else
xlpFile[0] = '\0';
search_paths[0] = curdir;
}
lstrcpyW(xlpFile, lpFile);
if (PathResolveW(xlpFile, search_paths, PRF_TRYPROGRAMEXTENSIONS | PRF_VERIFYEXISTS) ||
PathFindOnPathW(xlpFile, search_paths))
{
TRACE("PathResolveW returned non-zero\n");
lpFile = xlpFile;
PathRemoveBlanksW(xlpFile);
lstrcpyW(lpResult, xlpFile);
/* The file was found in lpPath or one of the directories in the system-wide search path */
}
else
{
xlpFile[0] = '\0';
}
attribs = GetFileAttributesW(lpFile);