From f87e25a7bc2a8917091a9d9d93139bb77eb1e154 Mon Sep 17 00:00:00 2001 From: Jason Edmeades Date: Mon, 10 Sep 2018 23:30:20 +0100 Subject: [PATCH] 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 Signed-off-by: Alexandre Julliard --- 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 bed395091e2..79233d8d6f4 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -1427,6 +1427,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 5cca037a306..797a9cc8aec 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -996,6 +996,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 c8a41d3a801..5ef4a2bf348 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -2308,12 +2308,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++; } }