[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
This commit is contained in:
Jose Carlos Jesus 2023-02-10 11:05:11 -04:00 committed by GitHub
parent 5c22ce3742
commit f691efefc2
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 25 deletions

View file

@ -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;
}

View file

@ -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))
{

View file

@ -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))