From: Jason Edmeades us@edmeades.me.uk
--- programs/cmd/tests/test_cmdline.cmd | 5 +++++ programs/cmd/tests/test_cmdline.cmd.exp | 2 ++ programs/cmd/wcmdmain.c | 7 +++++-- 3 files changed, 12 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/tests/test_cmdline.cmd b/programs/cmd/tests/test_cmdline.cmd index 8712f05f87d..8f3143d0700 100644 --- a/programs/cmd/tests/test_cmdline.cmd +++ b/programs/cmd/tests/test_cmdline.cmd @@ -52,6 +52,11 @@ echo No prompts or I would not get here1 rem - Try cmd.exe /k as well cmd.exe /k "copy file1 file2 >nul && exit" echo No prompts or I would not get here2 +rem Directories are ignored when searching for executable files +mkdir cmd.exe +cmd.exe /c echo alabaster +cmd /c echo chrome +rmdir cmd.exe
rem Nonexistent variable expansion is as per command line, i.e. left as-is cmd.exe /c echo %%hello1%% diff --git a/programs/cmd/tests/test_cmdline.cmd.exp b/programs/cmd/tests/test_cmdline.cmd.exp index 58cd5480292..cb9d306b487 100644 --- a/programs/cmd/tests/test_cmdline.cmd.exp +++ b/programs/cmd/tests/test_cmdline.cmd.exp @@ -32,6 +32,8 @@ No whitespace --- Test 18 No prompts or I would not get here1 No prompts or I would not get here2 +alabaster +chrome %hello1% %hello2 %hello3:h=t% diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 320a6daf0a1..af38fc7f04e 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -1546,6 +1546,7 @@ RETURN_CODE WCMD_run_program(WCHAR *command, BOOL called) WCHAR *pos = NULL; BOOL found = FALSE; BOOL inside_quotes = FALSE; + DWORD attribs;
if (explicit_path) { @@ -1604,7 +1605,8 @@ RETURN_CODE WCMD_run_program(WCHAR *command, BOOL called)
/* 1. If extension supplied, see if that file exists */ if (extensionsupplied) { - if (GetFileAttributesW(thisDir) != INVALID_FILE_ATTRIBUTES) { + attribs = GetFileAttributesW(thisDir); + if (attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY)) { found = TRUE; } } @@ -1634,7 +1636,8 @@ RETURN_CODE WCMD_run_program(WCHAR *command, BOOL called) thisExt = NULL; }
- if (GetFileAttributesW(thisDir) != INVALID_FILE_ATTRIBUTES) { + attribs = GetFileAttributesW(thisDir); + if (attribs != INVALID_FILE_ATTRIBUTES && !(attribs & FILE_ATTRIBUTE_DIRECTORY)) { found = TRUE; thisExt = NULL; }