Skip to content

Commit c7d1aa3

Browse files
[SHELL32] SHELL_FindExecutable: improve path handling code (reactos#7633)
Follow-up of 42d5dfd. - Revert "shell32: Fix ShellExecute for non-filespec paths." https://gitlab.winehq.org/wine/wine/-/commit/0bad544aab9e2c9ee93bbabac0386e02c58a39c0. - Apply "shell32: Look for the file name without extension also for the path search case." https://gitlab.winehq.org/wine/wine/-/commit/38b6640be91047b2cae71c103afed8a5b448542d. - 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
1 parent fe7a58d commit c7d1aa3

File tree

1 file changed

+20
-46
lines changed

1 file changed

+20
-46
lines changed

dll/win32/shell32/shlexec.cpp

Lines changed: 20 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -748,7 +748,7 @@ static UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpVerb,
748748
WCHAR wBuffer[256]; /* Used to GetProfileString */
749749
UINT retval = SE_ERR_NOASSOC;
750750
WCHAR *tok; /* token pointer */
751-
WCHAR xlpFile[MAX_PATH]; /* result of SearchPath */
751+
WCHAR xlpFile[MAX_PATH]; /* result of PathResolve */
752752
DWORD attribs; /* file attributes */
753753
WCHAR curdir[MAX_PATH];
754754
const WCHAR *search_paths[3] = {0};
@@ -777,55 +777,29 @@ static UINT SHELL_FindExecutable(LPCWSTR lpPath, LPCWSTR lpFile, LPCWSTR lpVerb,
777777
}
778778

779779
GetCurrentDirectoryW(ARRAY_SIZE(curdir), curdir);
780-
if (!PathIsFileSpecW(lpFile))
780+
if (lpPath && *lpPath)
781781
{
782-
BOOL found = FALSE;
783-
if (lpPath && *lpPath)
784-
{
785-
TRACE("lpPath %s\n", debugstr_w(lpPath));
786-
PathCombineW(xlpFile, lpPath, lpFile);
787-
if (PathFileExistsDefExtW(xlpFile, WHICH_DEFAULT | WHICH_OPTIONAL) || PathFileExistsW(xlpFile))
788-
{
789-
GetFullPathNameW(xlpFile, ARRAY_SIZE(xlpFile), xlpFile, NULL);
790-
found = TRUE;
791-
}
792-
}
793-
if (!found)
794-
{
795-
lstrcpyW(xlpFile, lpFile);
796-
if (PathFileExistsDefExtW(xlpFile, WHICH_DEFAULT | WHICH_OPTIONAL) || PathFileExistsW(xlpFile))
797-
{
798-
GetFullPathNameW(xlpFile, ARRAY_SIZE(xlpFile), xlpFile, NULL);
799-
found = TRUE;
800-
}
801-
}
802-
if (found)
803-
{
804-
lpFile = xlpFile;
805-
lstrcpyW(lpResult, xlpFile);
806-
}
807-
else
808-
xlpFile[0] = '\0';
782+
search_paths[0] = lpPath;
783+
search_paths[1] = curdir;
809784
}
810785
else
811786
{
812-
if (lpPath && *lpPath)
813-
{
814-
search_paths[0] = lpPath;
815-
search_paths[1] = curdir;
816-
}
817-
else
818-
search_paths[0] = curdir;
819-
lstrcpyW(xlpFile, lpFile);
820-
if (PathResolveW(xlpFile, search_paths, PRF_TRYPROGRAMEXTENSIONS | PRF_VERIFYEXISTS))
821-
{
822-
TRACE("PathResolveW returned non-zero\n");
823-
lpFile = xlpFile;
824-
lstrcpyW(lpResult, xlpFile);
825-
/* The file was found in lpPath or one of the directories in the system-wide search path */
826-
}
827-
else
828-
xlpFile[0] = '\0';
787+
search_paths[0] = curdir;
788+
}
789+
790+
lstrcpyW(xlpFile, lpFile);
791+
if (PathResolveW(xlpFile, search_paths, PRF_TRYPROGRAMEXTENSIONS | PRF_VERIFYEXISTS) ||
792+
PathFindOnPathW(xlpFile, search_paths))
793+
{
794+
TRACE("PathResolveW returned non-zero\n");
795+
lpFile = xlpFile;
796+
PathRemoveBlanksW(xlpFile);
797+
lstrcpyW(lpResult, xlpFile);
798+
/* The file was found in lpPath or one of the directories in the system-wide search path */
799+
}
800+
else
801+
{
802+
xlpFile[0] = '\0';
829803
}
830804

831805
attribs = GetFileAttributesW(lpFile);

0 commit comments

Comments
 (0)