https://git.reactos.org/?p=reactos.git;a=commitdiff;h=fc11cf78caf29d0a4539ea...
commit fc11cf78caf29d0a4539ea4777370714d447f5cb Author: Katayama Hirofumi MZ katayama.hirofumi.mz@gmail.com AuthorDate: Sun Mar 1 19:32:33 2020 +0900 Commit: GitHub noreply@github.com CommitDate: Sun Mar 1 19:32:33 2020 +0900
[SHELL32] Improve ShellExecCmdLine in path resolving (#2397)
Fix and improve private function shell32!ShellExecCmdLine to improve Run Dialog behavior. CORE-14409 --- dll/win32/shell32/shlexec.cpp | 31 +++++++++++++++---- .../rostests/apitests/shell32/ShellExecCmdLine.cpp | 36 ++++++++++++++++++---- 2 files changed, 55 insertions(+), 12 deletions(-)
diff --git a/dll/win32/shell32/shlexec.cpp b/dll/win32/shell32/shlexec.cpp index 3feab9c2ff6..3514c9c380a 100644 --- a/dll/win32/shell32/shlexec.cpp +++ b/dll/win32/shell32/shlexec.cpp @@ -2457,12 +2457,26 @@ HRESULT WINAPI ShellExecCmdLine( { PathAddBackslashW(szFile); } - if (SearchPathW(NULL, szFile, NULL, _countof(szFile2), szFile2, NULL) || - SearchPathW(NULL, szFile, wszExe, _countof(szFile2), szFile2, NULL) || - SearchPathW(NULL, szFile, wszCom, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, NULL, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, wszExe, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, wszCom, _countof(szFile2), szFile2, NULL)) + + WCHAR szCurDir[MAX_PATH]; + GetCurrentDirectoryW(_countof(szCurDir), szCurDir); + if (pwszStartDir) + { + SetCurrentDirectoryW(pwszStartDir); + } + + if (PathIsRelativeW(szFile) && + GetFullPathNameW(szFile, _countof(szFile2), szFile2, NULL) && + PathFileExistsW(szFile2)) + { + StringCchCopyW(szFile, _countof(szFile), szFile2); + } + else if (SearchPathW(NULL, szFile, NULL, _countof(szFile2), szFile2, NULL) || + SearchPathW(NULL, szFile, wszExe, _countof(szFile2), szFile2, NULL) || + SearchPathW(NULL, szFile, wszCom, _countof(szFile2), szFile2, NULL) || + SearchPathW(pwszStartDir, szFile, NULL, _countof(szFile2), szFile2, NULL) || + SearchPathW(pwszStartDir, szFile, wszExe, _countof(szFile2), szFile2, NULL) || + SearchPathW(pwszStartDir, szFile, wszCom, _countof(szFile2), szFile2, NULL)) { StringCchCopyW(szFile, _countof(szFile), szFile2); } @@ -2477,6 +2491,11 @@ HRESULT WINAPI ShellExecCmdLine( pchParams = NULL; }
+ if (pwszStartDir) + { + SetCurrentDirectoryW(szCurDir); + } + if (!(dwSeclFlags & SECL_ALLOW_NONEXE)) { if (!GetBinaryTypeW(szFile, &dwType)) diff --git a/modules/rostests/apitests/shell32/ShellExecCmdLine.cpp b/modules/rostests/apitests/shell32/ShellExecCmdLine.cpp index 1f2007a35e0..770c71c365f 100644 --- a/modules/rostests/apitests/shell32/ShellExecCmdLine.cpp +++ b/modules/rostests/apitests/shell32/ShellExecCmdLine.cpp @@ -133,12 +133,31 @@ HRESULT WINAPI ShellExecCmdLine( else { pchParams = SplitParams(lpCommand, szFile, _countof(szFile)); - if (SearchPathW(NULL, szFile, NULL, _countof(szFile2), szFile2, NULL) || - SearchPathW(NULL, szFile, wszExe, _countof(szFile2), szFile2, NULL) || - SearchPathW(NULL, szFile, wszCom, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, NULL, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, wszExe, _countof(szFile2), szFile2, NULL) || - SearchPathW(pwszStartDir, szFile, wszCom, _countof(szFile2), szFile2, NULL)) + if (szFile[0] != UNICODE_NULL && szFile[1] == L':' && + szFile[2] == UNICODE_NULL) + { + PathAddBackslashW(szFile); + } + + WCHAR szCurDir[MAX_PATH]; + GetCurrentDirectoryW(_countof(szCurDir), szCurDir); + if (pwszStartDir) + { + SetCurrentDirectoryW(pwszStartDir); + } + + if (PathIsRelativeW(szFile) && + GetFullPathNameW(szFile, _countof(szFile2), szFile2, NULL) && + PathFileExistsW(szFile2)) + { + StringCchCopyW(szFile, _countof(szFile), szFile2); + } + else if (SearchPathW(NULL, szFile, NULL, _countof(szFile2), szFile2, NULL) || + SearchPathW(NULL, szFile, wszExe, _countof(szFile2), szFile2, NULL) || + SearchPathW(NULL, szFile, wszCom, _countof(szFile2), szFile2, NULL) || + SearchPathW(pwszStartDir, szFile, NULL, _countof(szFile2), szFile2, NULL) || + SearchPathW(pwszStartDir, szFile, wszExe, _countof(szFile2), szFile2, NULL) || + SearchPathW(pwszStartDir, szFile, wszCom, _countof(szFile2), szFile2, NULL)) { StringCchCopyW(szFile, _countof(szFile), szFile2); } @@ -153,6 +172,11 @@ HRESULT WINAPI ShellExecCmdLine( pchParams = NULL; }
+ if (pwszStartDir) + { + SetCurrentDirectoryW(szCurDir); + } + if (!(dwSeclFlags & SECL_ALLOW_NONEXE)) { if (!GetBinaryTypeW(szFile, &dwType))