[PATCH 1/5] [cmd] cmd /c "pgmname" searches all extensions on PATHEXT
Ann and Jason Edmeades
jason at edmeades.me.uk
Mon Oct 15 18:53:23 CDT 2012
When searching for a valid executable, use all the extensions on
PATHEXT rather than hard coded exe/com. Specifically, the new tests
added last week show it searches for .bat/.cmd but manual tests
also confirm other extensions on pathext take effect (e.g. a vbs
file is launched if you do cmd /c "pgmname" only if vbs is on
pathext).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.winehq.org/pipermail/wine-patches/attachments/20121016/656f87b1/attachment.html>
-------------- next part --------------
From 12d71cfae6b703335d9b2a7cc2bf96d2ea90df49 Mon Sep 17 00:00:00 2001
From: Jason Edmeades <jason at edmeades.me.uk>
Date: Sat, 13 Oct 2012 21:50:22 +0100
Subject: [PATCH 1/5] [cmd] cmd /c "pgmname" searches all extensions on PATHEXT
When searching for a valid executable, use all the extensions on
PATHEXT rather than hard coded exe/com. Specifically, the new tests
added last week show it searches for .bat/.cmd but manual tests
also confirm other extensions on pathext take effect (e.g. a vbs
file is launched if you do cmd /c "pgmname" only if vbs is on
pathext).
---
programs/cmd/tests/test_cmdline.cmd.exp | 8 +--
programs/cmd/wcmdmain.c | 81 ++++++++++++++++++++-----------
2 files changed, 57 insertions(+), 32 deletions(-)
diff --git a/programs/cmd/tests/test_cmdline.cmd.exp b/programs/cmd/tests/test_cmdline.cmd.exp
index 7e9ac32..61deff6 100644
--- a/programs/cmd/tests/test_cmdline.cmd.exp
+++ b/programs/cmd/tests/test_cmdline.cmd.exp
@@ -60,7 +60,7 @@ var=33 at space@
@todo_wine at 4@space@
------ Testing invocation with CMD /C -------------
0 at space@
- at todo_wine@1 at space@
+1 at space@
@todo_wine at 0@space@
0 at space@
@todo_wine at 1@space@
@@ -74,7 +74,7 @@ var=33 at space@
"hi"
@todo_wine at 1@space@
"\"\\"\\\"\\\\"@space@"\"\\"\\\"\\\\"
- at todo_wine@1 at space@
+1 at space@
0 at space@
1 at space@
0 at space@
@@ -85,10 +85,10 @@ var=33 at space@
2 at space@
2 at space@
0 at space@
- at todo_wine@5 at space@
+5 at space@
------- Testing CMD /C qualifier treatment ------------
0 at space@
- at todo_wine@1 at space@
+1 at space@
THIS FAILS: cmd "/c"say one
THIS FAILS: cmd ignoreme/c say one
--------- Testing special characters --------------
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 7cd6bda..2aa116c 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -47,6 +47,11 @@ BOOL echo_mode = TRUE;
WCHAR anykey[100], version_string[100];
const WCHAR newlineW[] = {'\r','\n','\0'};
const WCHAR spaceW[] = {' ','\0'};
+static const WCHAR envPathExt[] = {'P','A','T','H','E','X','T','\0'};
+static const WCHAR dfltPathExt[] = {'.','b','a','t',';',
+ '.','c','o','m',';',
+ '.','c','m','d',';',
+ '.','e','x','e','\0'};
static BOOL opt_c, opt_k, opt_s, unicodeOutput = FALSE;
@@ -1009,7 +1014,6 @@ void WCMD_run_program (WCHAR *command, BOOL called)
BOOL assumeInternal = FALSE;
DWORD len;
static const WCHAR envPath[] = {'P','A','T','H','\0'};
- static const WCHAR envPathExt[] = {'P','A','T','H','E','X','T','\0'};
static const WCHAR delims[] = {'/','\\',':','\0'};
/* Quick way to get the filename
@@ -1055,10 +1059,6 @@ void WCMD_run_program (WCHAR *command, BOOL called)
/* Now extract PATHEXT */
len = GetEnvironmentVariableW(envPathExt, pathext, sizeof(pathext)/sizeof(WCHAR));
if ((len == 0) || (len >= (sizeof(pathext)/sizeof(WCHAR)))) {
- static const WCHAR dfltPathExt[] = {'.','b','a','t',';',
- '.','c','o','m',';',
- '.','c','m','d',';',
- '.','e','x','e','\0'};
strcpyW (pathext, dfltPathExt);
}
@@ -2445,10 +2445,15 @@ int wmain (int argc, WCHAR *argvW[])
is a valid executable, ie must exist, otherwise drop back to old mode */
if (!opt_s) {
WCHAR *thisArg = WCMD_parameter(cmd, 0, NULL, NULL, FALSE);
- static const WCHAR extEXEW[] = {'.','e','x','e','\0'};
- static const WCHAR extCOMW[] = {'.','c','o','m','\0'};
+ WCHAR pathext[MAXSTRING];
BOOL found = FALSE;
+ /* Now extract PATHEXT */
+ len = GetEnvironmentVariableW(envPathExt, pathext, sizeof(pathext)/sizeof(WCHAR));
+ if ((len == 0) || (len >= (sizeof(pathext)/sizeof(WCHAR)))) {
+ strcpyW (pathext, dfltPathExt);
+ }
+
/* If the supplied parameter has any directory information, look there */
WINE_TRACE("First parameter is '%s'\n", wine_dbgstr_w(thisArg));
if (strchrW(thisArg, '\\') != NULL) {
@@ -2461,18 +2466,28 @@ int wmain (int argc, WCHAR *argvW[])
if (GetFileAttributesW(string) != INVALID_FILE_ATTRIBUTES) {
WINE_TRACE("Found file as '%s'\n", wine_dbgstr_w(string));
found = TRUE;
- } else strcpyW(p, extEXEW);
-
- /* Does file exist with .exe appended */
- if (!found && GetFileAttributesW(string) != INVALID_FILE_ATTRIBUTES) {
- WINE_TRACE("Found file as '%s'\n", wine_dbgstr_w(string));
- found = TRUE;
- } else strcpyW(p, extCOMW);
+ } else {
+ WCHAR *thisExt = pathext;
+
+ /* No - try with each of the PATHEXT extensions */
+ while (!found && thisExt) {
+ WCHAR *nextExt = strchrW(thisExt, ';');
+
+ if (nextExt) {
+ memcpy(p, thisExt, (nextExt-thisExt) * sizeof(WCHAR));
+ p[(nextExt-thisExt)] = 0x00;
+ thisExt = nextExt+1;
+ } else {
+ strcpyW(p, thisExt);
+ thisExt = NULL;
+ }
- /* Does file exist with .com appended */
- if (!found && GetFileAttributesW(string) != INVALID_FILE_ATTRIBUTES) {
- WINE_TRACE("Found file as '%s'\n", wine_dbgstr_w(string));
- found = TRUE;
+ /* Does file exist with this extension appended? */
+ if (GetFileAttributesW(string) != INVALID_FILE_ATTRIBUTES) {
+ WINE_TRACE("Found file as '%s'\n", wine_dbgstr_w(string));
+ found = TRUE;
+ }
+ }
}
/* Otherwise we now need to look in the path to see if we can find it */
@@ -2483,18 +2498,28 @@ int wmain (int argc, WCHAR *argvW[])
if (SearchPathW(NULL, thisArg, NULL, sizeof(string)/sizeof(WCHAR), string, NULL) != 0) {
WINE_TRACE("Found on path as '%s'\n", wine_dbgstr_w(string));
found = TRUE;
- }
+ } else {
+ WCHAR *thisExt = pathext;
- /* Does file exist plus an extension of .exe? */
- if (SearchPathW(NULL, thisArg, extEXEW, sizeof(string)/sizeof(WCHAR), string, NULL) != 0) {
- WINE_TRACE("Found on path as '%s'\n", wine_dbgstr_w(string));
- found = TRUE;
- }
+ /* No - try with each of the PATHEXT extensions */
+ while (!found && thisExt) {
+ WCHAR *nextExt = strchrW(thisExt, ';');
- /* Does file exist plus an extension of .com? */
- if (SearchPathW(NULL, thisArg, extCOMW, sizeof(string)/sizeof(WCHAR), string, NULL) != 0) {
- WINE_TRACE("Found on path as '%s'\n", wine_dbgstr_w(string));
- found = TRUE;
+ if (nextExt) {
+ *nextExt = 0;
+ nextExt = nextExt+1;
+ } else {
+ nextExt = NULL;
+ }
+
+ /* Does file exist with this extension? */
+ if (SearchPathW(NULL, thisArg, thisExt, sizeof(string)/sizeof(WCHAR), string, NULL) != 0) {
+ WINE_TRACE("Found on path as '%s' with extension '%s'\n", wine_dbgstr_w(string),
+ wine_dbgstr_w(thisExt));
+ found = TRUE;
+ }
+ thisExt = nextExt;
+ }
}
}
--
1.7.9.5
More information about the wine-patches
mailing list