From f691efefc26ef554e9715abfa1916527277599bb Mon Sep 17 00:00:00 2001 From: Jose Carlos Jesus Date: Fri, 10 Feb 2023 11:05:11 -0400 Subject: [PATCH] [SHLWAPI] No need extension to execute '.bat' files CORE-17612 (#4932) When no extension is provided, add default extension with correct precedence using PathFileExistsDefExtW. - Use PathFindOnPathExW when searching in current directory and PATH environment variable. - Fix Width String terminator to UNICODE_NULL. - Fix all failed tests on PathFindPathExW KVM test. CORE-17612 --- dll/win32/kernel32/client/path.c | 4 ++-- dll/win32/shell32/shlexec.cpp | 28 +++++----------------------- dll/win32/shlwapi/path.c | 1 + 3 files changed, 8 insertions(+), 25 deletions(-) diff --git a/dll/win32/kernel32/client/path.c b/dll/win32/kernel32/client/path.c index 1fa09d530c8..ea014bb512d 100644 --- a/dll/win32/kernel32/client/path.c +++ b/dll/win32/kernel32/client/path.c @@ -2321,7 +2321,7 @@ GetSystemDirectoryW(OUT LPWSTR lpBuffer, RtlCopyMemory(lpBuffer, BaseWindowsSystemDirectory.Buffer, BaseWindowsSystemDirectory.Length); - lpBuffer[BaseWindowsSystemDirectory.Length / sizeof(WCHAR)] = ANSI_NULL; + lpBuffer[BaseWindowsSystemDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL; ReturnLength = BaseWindowsSystemDirectory.Length; } @@ -2405,7 +2405,7 @@ GetSystemWindowsDirectoryW(OUT LPWSTR lpBuffer, RtlCopyMemory(lpBuffer, BaseWindowsDirectory.Buffer, BaseWindowsDirectory.Length); - lpBuffer[BaseWindowsDirectory.Length / sizeof(WCHAR)] = ANSI_NULL; + lpBuffer[BaseWindowsDirectory.Length / sizeof(WCHAR)] = UNICODE_NULL; ReturnLength = BaseWindowsDirectory.Length; } diff --git a/dll/win32/shell32/shlexec.cpp b/dll/win32/shell32/shlexec.cpp index 746c92076bb..292c8db8292 100644 --- a/dll/win32/shell32/shlexec.cpp +++ b/dll/win32/shell32/shlexec.cpp @@ -2531,6 +2531,8 @@ HRESULT WINAPI ShellExecCmdLine( } else { + PCWSTR apPathList[2]; + pchParams = SplitParams(lpCommand, szFile, _countof(szFile)); if (szFile[0] != UNICODE_NULL && szFile[1] == L':' && szFile[2] == UNICODE_NULL) @@ -2551,30 +2553,10 @@ HRESULT WINAPI ShellExecCmdLine( { StringCchCopyW(szFile, _countof(szFile), szFile2); } - else if (SearchPathW(NULL, szFile, NULL, _countof(szFile2), szFile2, NULL) || - SearchPathW(NULL, szFile, L".exe", _countof(szFile2), szFile2, NULL) || - SearchPathW(NULL, szFile, L".com", _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, NULL, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, L".exe", _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, L".com", _countof(szFile2), szFile2, NULL)) - { - StringCchCopyW(szFile, _countof(szFile), szFile2); - } - else if (SearchPathW(NULL, lpCommand, NULL, _countof(szFile2), szFile2, NULL) || - SearchPathW(NULL, lpCommand, L".exe", _countof(szFile2), szFile2, NULL) || - SearchPathW(NULL, lpCommand, L".com", _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, lpCommand, NULL, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, lpCommand, L".exe", _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, lpCommand, L".com", _countof(szFile2), szFile2, NULL)) - { - StringCchCopyW(szFile, _countof(szFile), szFile2); - pchParams = NULL; - } - if (pwszStartDir) - { - SetCurrentDirectoryW(szCurDir); - } + apPathList[0] = pwszStartDir; + apPathList[1] = NULL; + PathFindOnPathExW(szFile, apPathList, WHICH_DEFAULT); if (!(dwSeclFlags & SECL_ALLOW_NONEXE)) { diff --git a/dll/win32/shlwapi/path.c b/dll/win32/shlwapi/path.c index fc698251cf2..2966a8bf93b 100644 --- a/dll/win32/shlwapi/path.c +++ b/dll/win32/shlwapi/path.c @@ -1151,6 +1151,7 @@ BOOL WINAPI PathFileExistsDefExtW(LPWSTR lpszPath,DWORD dwWhich) #ifdef __REACTOS__ if (dwWhich & 0x1) { + if (GetFileAttributes(lpszPath) != FILE_ATTRIBUTE_DIRECTORY) #endif lstrcpyW(lpszPath + iLen, pszExts[iChoose]); if (PathFileExistsW(lpszPath))