[PATCH 3/3] [programs/cmd] Handle unechoed rem commands inside a (..) section
Jason Edmeades
us at edmeades.me.uk
Mon Sep 10 17:30:20 CDT 2018
Fixes bug#45729
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.
Signed-off-by: Jason Edmeades <us at edmeades.me.uk>
---
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 bed395091e..79233d8d6f 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 5cca037a30..797a9cc8ae 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 c8a41d3a80..5ef4a2bf34 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++;
}
}
--
2.17.1
More information about the wine-devel
mailing list