[PATCH] cmd: Avoid having first parameter to start.exe ignored.

Dmitry Timoshkov dmitry at baikal.ru
Fri Apr 27 04:57:42 CDT 2018


From: Bernhard Übelacker <bernhardu at mailbox.org>

I haven't found the reasons why this patch hasn't been accepted, so
I decided to resend it. Besides that it fixes the problems listed in
the referenced bug report it also fixes execution of a .bat file that
an application that I have here installs as the command in the .job
file for the task scheduler.

Comments from the original submission:
-------------------------------------------------------------------------
https://bugs.winehq.org/show_bug.cgi?id=44334

Found while trying to look into #44236.
A batch script is executed but the start commands
do not wait until the started process ends.

Example line:
---
start /W  " "  "%SFDIR%automesh"  wr2300
---

As far as I see this happens when WCMD_start encounters an title parameter.
Then it removes the executable from the cmdline parameter to CreateProcessW.
---
start /W "" notepad
002f:trace:process:create_process_impl app L"C:\\windows\\command\\start.exe" cmdline L"/W \"\\\"\\\"\" notepad"
---
This get not recognized much, because usually the title is the first
parameter and is therefore ignored by start.exe.

This patch tries to maintain the executable as first parameter in the
cmdline parameter to CreateProcessW.

Signed-off-by: Bernhard Übelacker <bernhardu at mailbox.org>
Signed-off-by: Dmitry Timoshkov <dmitry at baikal.ru>
---
 programs/cmd/builtins.c                  | 15 ++++++++-------
 programs/cmd/tests/test_builtins.cmd     |  4 ++++
 programs/cmd/tests/test_builtins.cmd.exp |  2 ++
 3 files changed, 14 insertions(+), 7 deletions(-)

diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index ec66cd5724..04b098e98d 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -4322,7 +4322,7 @@ void WCMD_start(WCHAR *args)
     int argno;
     int have_title;
     WCHAR file[MAX_PATH];
-    WCHAR *cmdline;
+    WCHAR *cmdline, *cmdline_params;
     STARTUPINFOW st;
     PROCESS_INFORMATION pi;
 
@@ -4331,6 +4331,7 @@ void WCMD_start(WCHAR *args)
     cmdline = heap_alloc( (strlenW(file) + strlenW(args) + 8) * sizeof(WCHAR) );
     strcpyW( cmdline, file );
     strcatW( cmdline, spaceW );
+    cmdline_params = cmdline + strlenW(cmdline);
 
     /* The start built-in has some special command-line parsing properties
      * which will be outlined here.
@@ -4382,17 +4383,17 @@ void WCMD_start(WCHAR *args)
             have_title = TRUE;
 
             /* Copy all of the cmdline processed */
-            memcpy(cmdline, args, sizeof(WCHAR) * (argN - args));
-            cmdline[argN - args] = '\0';
+            memcpy(cmdline_params, args, sizeof(WCHAR) * (argN - args));
+            cmdline_params[argN - args] = '\0';
 
             /* Add quoted title */
-            strcatW(cmdline, prefixQuote);
-            strcatW(cmdline, thisArg);
-            strcatW(cmdline, postfixQuote);
+            strcatW(cmdline_params, prefixQuote);
+            strcatW(cmdline_params, thisArg);
+            strcatW(cmdline_params, postfixQuote);
 
             /* Concatenate remaining command-line */
             thisArg = WCMD_parameter_with_delims(args, argno, &argN, TRUE, FALSE, startDelims);
-            strcatW(cmdline, argN + strlenW(thisArg));
+            strcatW(cmdline_params, argN + strlenW(thisArg));
 
             break;
         }
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index f6846283c7..63ec3cacb1 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -2988,6 +2988,10 @@ path
 set path=%WINE_backup_path%
 set WINE_backup_path=
 
+echo ------------ Testing start /W ------------
+echo start /W failed to wait>foobar.txt
+start /W "" cmd /C "ping -n1 & echo start /W seems to really wait>foobar.txt"& type foobar.txt& del foobar.txt
+
 echo ------------ Testing combined CALLs/GOTOs ------------
 echo @echo off>foo.cmd
 echo goto :eof>>foot.cmd
diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp
index 4663c862fa..dcc96299b9 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -1574,6 +1574,8 @@ Correctly ignored trailing information
 PATH=original
 PATH=try2
 PATH=try3
+------------ Testing start /W ------------
+start /W seems to really wait
 ------------ Testing combined CALLs/GOTOs ------------
 world
 cheball
-- 
2.16.3




More information about the wine-devel mailing list