Fixes https://bugs.winehq.org/show_bug.cgi?id=44133
Signed-off-by: Vijay Kiran Kamuju infyquest@gmail.com --- programs/cmd/builtins.c | 2 +- programs/cmd/wcmd.h | 1 + programs/cmd/wcmdmain.c | 8 +++++--- 3 files changed, 7 insertions(+), 4 deletions(-)
diff --git a/programs/cmd/builtins.c b/programs/cmd/builtins.c index 0609bb7f3fb..3b0a4b5f0c3 100644 --- a/programs/cmd/builtins.c +++ b/programs/cmd/builtins.c @@ -1470,7 +1470,7 @@ BOOL WCMD_delete (WCHAR *args) { * Pre: s non NULL * */ -static WCHAR *WCMD_strtrim(const WCHAR *s) +WCHAR *WCMD_strtrim(const WCHAR *s) { DWORD len = strlenW(s); const WCHAR *start = s; diff --git a/programs/cmd/wcmd.h b/programs/cmd/wcmd.h index d4d97a0067e..321b9263a06 100644 --- a/programs/cmd/wcmd.h +++ b/programs/cmd/wcmd.h @@ -112,6 +112,7 @@ WCHAR *WCMD_parameter (WCHAR *s, int n, WCHAR **start, BOOL raw, BOOL wholecmdli WCHAR *WCMD_parameter_with_delims (WCHAR *s, int n, WCHAR **start, BOOL raw, BOOL wholecmdline, const WCHAR *delims); WCHAR *WCMD_skip_leading_spaces (WCHAR *string); +WCHAR *WCMD_strtrim(const WCHAR *string); BOOL WCMD_keyword_ws_found(const WCHAR *keyword, int len, const WCHAR *ptr); void WCMD_HandleTildaModifiers(WCHAR **start, BOOL atExecute);
diff --git a/programs/cmd/wcmdmain.c b/programs/cmd/wcmdmain.c index 827ddd21219..f4729448b27 100644 --- a/programs/cmd/wcmdmain.c +++ b/programs/cmd/wcmdmain.c @@ -1680,15 +1680,17 @@ static void WCMD_addCommand(WCHAR *command, int *commandLen, CMD_LIST **lastEntry, CMD_LIST **output) {
CMD_LIST *thisEntry = NULL; + WCHAR *trimcmd = WCMD_strtrim(command); + int trimlen = strlenW(trimcmd);
/* Allocate storage for command */ thisEntry = heap_alloc(sizeof(CMD_LIST));
/* Copy in the command */ if (command) { - thisEntry->command = heap_alloc((*commandLen+1) * sizeof(WCHAR)); - memcpy(thisEntry->command, command, *commandLen * sizeof(WCHAR)); - thisEntry->command[*commandLen] = 0x00; + thisEntry->command = heap_alloc((trimlen+1) * sizeof(WCHAR)); + memcpy(thisEntry->command, trimcmd, trimlen * sizeof(WCHAR)); + thisEntry->command[trimlen] = 0x00;
/* Copy in the redirects */ thisEntry->redirects = heap_alloc((*redirLen+1) * sizeof(WCHAR));