From 68fd74e7f9bdd2310aebeb59bc86754271cdc063 Mon Sep 17 00:00:00 2001 From: Paul Gofman Date: Wed, 25 Oct 2023 14:23:20 -0600 Subject: [PATCH] shell32: Use SearchPathW() for %l/%L in SHELL_ArgifyW(). --- dlls/shell32/shlexec.c | 13 +++++++++---- dlls/shell32/tests/shlexec.c | 27 ++++++++++++++++++++++++++- 2 files changed, 35 insertions(+), 5 deletions(-) diff --git a/dlls/shell32/shlexec.c b/dlls/shell32/shlexec.c index b31f800e92a..e0a768012e6 100644 --- a/dlls/shell32/shlexec.c +++ b/dlls/shell32/shlexec.c @@ -77,7 +77,7 @@ static BOOL SHELL_ArgifyW(WCHAR* out, int len, const WCHAR* fmt, const WCHAR* lp BOOL found_p1 = FALSE; PWSTR res = out; PCWSTR cmd; - DWORD used = 0; + DWORD size, used = 0; TRACE("%p, %d, %s, %s, %p, %p\n", out, len, debugstr_w(fmt), debugstr_w(lpFile), pidl, args); @@ -164,11 +164,16 @@ static BOOL SHELL_ArgifyW(WCHAR* out, int len, const WCHAR* fmt, const WCHAR* lp case 'l': case 'L': if (lpFile) { - used += lstrlenW(lpFile); + if ((size = SearchPathW(NULL, lpFile, L".exe", ARRAY_SIZE(xlpFile), xlpFile, NULL) + && size <= ARRAY_SIZE(xlpFile))) + cmd = xlpFile; + else + cmd = lpFile; + used += lstrlenW(cmd); if (used < len) { - lstrcpyW(res, lpFile); - res += lstrlenW(lpFile); + lstrcpyW(res, cmd); + res += lstrlenW(cmd); } } found_p1 = TRUE; diff --git a/dlls/shell32/tests/shlexec.c b/dlls/shell32/tests/shlexec.c index 90e96b91586..11332484800 100644 --- a/dlls/shell32/tests/shlexec.c +++ b/dlls/shell32/tests/shlexec.c @@ -1624,7 +1624,7 @@ static void test_argify(void) static void test_filename(void) { - char filename[MAX_PATH + 20]; + char filename[MAX_PATH + 20], curdir[MAX_PATH]; const filename_tests_t* test; char* c; INT_PTR rc; @@ -1635,6 +1635,31 @@ static void test_filename(void) return; } + GetCurrentDirectoryA(sizeof(curdir), curdir); + + SetCurrentDirectoryA(tmpdir); + rc=shell_execute("QuotedLowerL", "simple.shlexec", NULL, NULL); + if (rc > 32) + rc=33; + okShell(rc == 33, "failed: rc=%Id err=%lu\n", rc, GetLastError()); + okChildInt("argcA", 5); + okChildString("argvA3", "QuotedLowerL"); + strcpy(filename, tmpdir); + strcat(filename, "\\simple.shlexec"); + okChildPath("argvA4", filename); + + rc=shell_execute("QuotedUpperL", "simple.shlexec", NULL, NULL); + if (rc > 32) + rc=33; + okShell(rc == 33, "failed: rc=%Id err=%lu\n", rc, GetLastError()); + okChildInt("argcA", 5); + okChildString("argvA3", "QuotedUpperL"); + strcpy(filename, tmpdir); + strcat(filename, "\\simple.shlexec"); + okChildPath("argvA4", filename); + + SetCurrentDirectoryA(curdir); + test=filename_tests; while (test->basename) { -- 2.11.4.GIT