https://bugs.winehq.org/show_bug.cgi?id=40694
Signed-off-by: Vijay Kiran Kamuju infyquest@gmail.com --- programs/cmd/tests/test_cmdline.cmd | 4 ++++ programs/cmd/wcmdmain.c | 7 +++++-- 2 files changed, 9 insertions(+), 2 deletions(-)
diff --git a/programs/cmd/tests/test_cmdline.cmd b/programs/cmd/tests/test_cmdline.cmd index 32a1ef2e48f..caac7b07144 100644 --- a/programs/cmd/tests/test_cmdline.cmd +++ b/programs/cmd/tests/test_cmdline.cmd @@ -86,6 +86,10 @@ cmd.exe /c ECHO %%VAR%% rem - Exit works cmd.exe /c exit
+rem - Change drive +cmd.exe /c C: +cmd.exe /c "C: &" +cmd.exe /c "C: > NUL" cd .. rd foobar /s /q
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 827ddd21219..f89bd04e650 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -1686,9 +1686,12 @@ static void WCMD_addCommand(WCHAR *command, int *commandLen,
/* Copy in the command */ if (command) { + WCHAR *tend = command + *commandLen + 1; thisEntry->command = heap_alloc((*commandLen+1) * sizeof(WCHAR)); - memcpy(thisEntry->command, command, *commandLen * sizeof(WCHAR)); - thisEntry->command[*commandLen] = 0x00; + while (tend > command && isspaceW(*tend)) tend--; + memcpy(thisEntry->command, command, (tend - command + 2) * sizeof(WCHAR)); + thisEntry->command[tend - command + 1] = 0x00; + heap_free(tend);
/* Copy in the redirects */ thisEntry->redirects = heap_alloc((*redirLen+1) * sizeof(WCHAR));