Module: wine
Branch: stable
Commit: 473a565dd2aaff412377ff4446f04c39454c1ff5
URL: https://source.winehq.org/git/wine.git/?a=commit;h=473a565dd2aaff412377ff44…
Author: Jason Edmeades <us(a)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(a)edmeades.me.uk>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
(cherry picked from commit 15215bd07193cc31b8372424f181a31aa9364777)
Signed-off-by: Michael Stefaniuc <mstefani(a)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@
Module: wine
Branch: stable
Commit: 101fc687335df5fd695055d818082958197ca2ab
URL: https://source.winehq.org/git/wine.git/?a=commit;h=101fc687335df5fd695055d8…
Author: Jason Edmeades <us(a)edmeades.me.uk>
Date: Wed Jul 4 22:08:38 2018 +0100
cmd: Support "c:<space>" etc when changing drive letters.
This allows whitespace and any other text on the line when changing drive letters.
Mostly I expect it crops up when commands are concatenated and the readability
whitespace is added to the end of the command. For example C: & dir results in
"C: " and "dir" as the two commands. We cannot unconditionally remove whitespace
as some commands rely on it.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=40694
Signed-off-by: Jason Edmeades <us(a)edmeades.me.uk>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
(cherry picked from commit daee8b753c52011d1dd745e399cbe25ac9e9ac47)
Signed-off-by: Michael Stefaniuc <mstefani(a)winehq.org>
---
programs/cmd/tests/test_builtins.cmd | 35 ++++++++++++++++++++++++++++++++
programs/cmd/tests/test_builtins.cmd.exp | 7 +++++++
programs/cmd/wcmdmain.c | 9 ++++++--
3 files changed, 49 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/tests/test_builtins.cmd b/programs/cmd/tests/test_builtins.cmd
index 63ec3ca..d060ba0 100644
--- a/programs/cmd/tests/test_builtins.cmd
+++ b/programs/cmd/tests/test_builtins.cmd
@@ -2992,6 +2992,41 @@ 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 changing the drive letter ----------
+pushd C:\
+
+echo Normal:
+call :setError 0
+C:
+if errorlevel 1 echo Normal drive change failed
+
+echo Normal+space
+call :setError 0
+C:@space@
+if errorlevel 1 echo Normal+space drive change failed
+
+echo Normal+space+garbage
+call :setError 0
+C: garbage
+if errorlevel 1 echo Normal+space+garbage drive change failed
+
+call :setError 0
+echo Quoted should fail
+"C:"
+if not errorlevel 1 echo quoted drive change unexpectedly worked
+
+echo Normal+tab
+call :setError 0
+C:@tab@
+if errorlevel 1 echo Normal+tab drive change failed
+
+echo Normal+tab+garbage
+call :setError 0
+C:@tab@garbagetab
+if errorlevel 1 echo Normal+tab+garbage drive change failed
+
+popd
+
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 dcc9629..e2b94af 100644
--- a/programs/cmd/tests/test_builtins.cmd.exp
+++ b/programs/cmd/tests/test_builtins.cmd.exp
@@ -1576,6 +1576,13 @@ PATH=try2
PATH=try3
------------ Testing start /W ------------
start /W seems to really wait
+------------ Testing changing the drive letter ----------
+Normal:
+Normal+space
+Normal+space+garbage
+Quoted should fail
+Normal+tab
+Normal+tab+garbage
------------ Testing combined CALLs/GOTOs ------------
world
cheball
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c
index 827ddd2..0d02f1f 100644
--- a/programs/cmd/wcmdmain.c
+++ b/programs/cmd/wcmdmain.c
@@ -1327,13 +1327,18 @@ void WCMD_execute (const WCHAR *command, const WCHAR *redirects,
cmd = new_cmd;
/*
- * Changing default drive has to be handled as a special case.
+ * Changing default drive has to be handled as a special case, anything
+ * else if it exists after whitespace is ignored
*/
- if ((strlenW(cmd) == 2) && (cmd[1] == ':') && IsCharAlphaW(cmd[0])) {
+ if ((cmd[1] == ':') && IsCharAlphaW(cmd[0]) &&
+ (!cmd[2] || cmd[2] == ' ' || cmd[2] == '\t')) {
WCHAR envvar[5];
WCHAR dir[MAX_PATH];
+ /* Ignore potential garbage on the same line */
+ cmd[2]=0x00;
+
/* According to MSDN CreateProcess docs, special env vars record
the current directory on each drive, in the form =C:
so see if one specified, and if so go back to it */
Module: wine
Branch: stable
Commit: 554f6cf9aa01af54fb6d5aeed48394ae5de8bed5
URL: https://source.winehq.org/git/wine.git/?a=commit;h=554f6cf9aa01af54fb6d5aee…
Author: Jason Edmeades <us(a)edmeades.me.uk>
Date: Wed Jul 4 22:08:40 2018 +0100
cmd: Fix issue in WCMD_assoc highlighted by valgrind.
In an error condition, the wrong variable was being used for an insert,
resulting in a read from uninitialized data. This could be triggered for
example by 'ftype jason=', and the error message should have included
jason but instead was just ''.
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=38849
Signed-off-by: Jason Edmeades <us(a)edmeades.me.uk>
Signed-off-by: Alexandre Julliard <julliard(a)winehq.org>
(cherry picked from commit ab46a89c3b8649844a70ee30abffbbd275128bc3)
Signed-off-by: Michael Stefaniuc <mstefani(a)winehq.org>
---
programs/cmd/builtins.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c
index 04b098e..3648f29 100644
--- a/programs/cmd/builtins.c
+++ b/programs/cmd/builtins.c
@@ -4883,7 +4883,7 @@ void WCMD_assoc (const WCHAR *args, BOOL assoc) {
LoadStringW(hinst, WCMD_NOFTYPE, msgbuffer,
sizeof(msgbuffer)/sizeof(WCHAR));
}
- WCMD_output_stderr(msgbuffer, keyValue);
+ WCMD_output_stderr(msgbuffer, args);
errorlevel = 2;
}