Module: wine Branch: stable Commit: 12242ae0769864cb46881145d6a5f2c70b3f3fea URL: https://source.winehq.org/git/wine.git/?a=commit;h=12242ae0769864cb46881145d...
Author: Jason Edmeades us@edmeades.me.uk Date: Mon Sep 10 23:30:20 2018 +0100
cmd: Handle unechoed rem commands inside a (..) section.
When processing a (..) multiline section, each line is processed and if it starts with a '@' it is not echoed, but more importantly if is 'rem' then anything else on that line should be ignored. The reported issue was that a pipe was being executed when it was hidden behind a rem, which was trigged by the preceeding '@' character not being skipped.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=45729 Signed-off-by: Jason Edmeades us@edmeades.me.uk Signed-off-by: Alexandre Julliard julliard@winehq.org (cherry picked from commit f87e25a7bc2a8917091a9d9d93139bb77eb1e154) Signed-off-by: Michael Stefaniuc mstefani@winehq.org
---
programs/cmd/tests/test_builtins.cmd | 6 ++++++ programs/cmd/tests/test_builtins.cmd.exp | 1 + programs/cmd/wcmdmain.c | 13 +++++++++++-- 3 files changed, 18 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index fd63e4e..cf9a986 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -1355,6 +1355,12 @@ for /L %%i in (2,2,1) do ( echo %%i echo FAILED ) +echo --- rems inside for loops +for /f %%i IN ("hello") DO ( + REM foo|echo ERROR unexpected execution 1 + @REM foo|echo ERROR unexpected execution 2 + @ REM foo|echo ERROR unexpected execution 3 +) echo --- ifs inside for loops for %%i in (test) do ( echo a1 diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index 30df08a..dd8d1d4 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -981,6 +981,7 @@ ErrorLevel 0 -1 1 3 +--- rems inside for loops --- ifs inside for loops a1 b1 diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 5135be4..f1a2679 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -2271,12 +2271,21 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
} while (*extraData == 0x00); curPos = extraSpace; - if (context) handleExpansion(extraSpace, FALSE, FALSE); + + /* Skip preceding whitespace */ + while (*curPos == ' ' || *curPos == '\t') curPos++; + + /* Replace env vars if in a batch context */ + if (context) handleExpansion(curPos, FALSE, FALSE); + /* Continue to echo commands IF echo is on and in batch program */ - if (context && echo_mode && extraSpace[0] && (extraSpace[0] != '@')) { + if (context && echo_mode && *curPos && *curPos != '@') { WCMD_output_asis(extraSpace); WCMD_output_asis(newlineW); } + + /* Skip repeated 'no echo' characters and whitespace */ + while (*curPos == '@' || *curPos == ' ' || *curPos == '\t') curPos++; } }