Module: wine Branch: stable Commit: 473a565dd2aaff412377ff4446f04c39454c1ff5 URL: https://source.winehq.org/git/wine.git/?a=commit;h=473a565dd2aaff412377ff444...
Author: Jason Edmeades us@edmeades.me.uk Date: Sun Jun 24 21:44:11 2018 +0100
cmd: Fix subdirectory prefix in for loops.
A for loop can be working through a wildcarded subdirectory, but when processing the first file in the subdirectory, it stores the prefix in a static variable which gets overwritten during the 'for' body processing.
Signed-off-by: Jason Edmeades us@edmeades.me.uk Signed-off-by: Alexandre Julliard julliard@winehq.org (cherry picked from commit 15215bd07193cc31b8372424f181a31aa9364777) Signed-off-by: Michael Stefaniuc mstefani@winehq.org
---
programs/cmd/builtins.c | 10 ++++++++-- programs/cmd/tests/test_builtins.cmd | 7 +++++++ programs/cmd/tests/test_builtins.cmd.exp | 4 ++++ 3 files changed, 19 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 3648f29..7c2122e 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -2261,19 +2261,25 @@ void WCMD_for (WCHAR *p, CMD_LIST **cmdList) { thisSet->bracketDepth >= thisDepth) {
/* Loop through all entries on the same line */ - WCHAR *item; + WCHAR *staticitem; WCHAR *itemStart; WCHAR buffer[MAXSTRING];
WINE_TRACE("Processing for set %p\n", thisSet); i = 0; - while (*(item = WCMD_parameter (thisSet->command, i, &itemStart, TRUE, FALSE))) { + while (*(staticitem = WCMD_parameter (thisSet->command, i, &itemStart, TRUE, FALSE))) {
/* * If the parameter within the set has a wildcard then search for matching files * otherwise do a literal substitution. */ static const WCHAR wildcards[] = {'*','?','\0'}; + + /* Take a copy of the item returned from WCMD_parameter as it is held in a + static buffer which can be overwritten during parsing of the for body */ + WCHAR item[MAXSTRING]; + strcpyW(item, staticitem); + thisCmdStart = cmdStart;
itemNum++; diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd index d060ba0..f344de2 100644 --- a/programs/cmd/tests/test_builtins.cmd +++ b/programs/cmd/tests/test_builtins.cmd @@ -1112,9 +1112,16 @@ mkdir foobar & cd foobar mkdir foo mkdir bar mkdir baz +mkdir pop echo > bazbaz echo --- basic wildcards for %%i in (ba*) do echo %%i +echo --- wildcards in subdirs +echo something>pop\bar1 +echo something>pop\bar2.txt +echo something>pop\bar3 +for %%f in (pop\ba*) do ( call echo %%f ) +rmdir /s/q pop echo --- for /d for /d %%i in (baz foo bar) do echo %%i 2>&1 rem Confirm we don't match files: diff --git a/programs/cmd/tests/test_builtins.cmd.exp b/programs/cmd/tests/test_builtins.cmd.exp index e2b94af..cab4a35 100644 --- a/programs/cmd/tests/test_builtins.cmd.exp +++ b/programs/cmd/tests/test_builtins.cmd.exp @@ -909,6 +909,10 @@ B C B D --- basic wildcards bazbaz +--- wildcards in subdirs +pop\bar1@space@ +pop\bar2.txt@space@ +pop\bar3@space@ --- for /d baz@space@ foo@space@