Skip to content

Commit

Permalink
cmd: Fix crash in if condition parsing.
Browse files Browse the repository at this point in the history
Regression introduced in f238e84.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=47770
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48738
Signed-off-by: Bernhard Übelacker <bernhardu@mailbox.org>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
  • Loading branch information
bernhardu authored and julliard committed May 4, 2020
1 parent ab5e48f commit b1e91a3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 8 deletions.
6 changes: 6 additions & 0 deletions programs/cmd/builtins.c
Original file line number Diff line number Diff line change
Expand Up @@ -2938,9 +2938,15 @@ void WCMD_if (WCHAR *p, CMD_LIST **cmdList)
int test; /* Condition evaluation result */
WCHAR *command;

/* Function evaluate_if_condition relies on the global variables quals, param1 and param2
set in a call to WCMD_parse before */
if (evaluate_if_condition(p, &command, &test, &negate) == -1)
goto syntax_err;

WINE_TRACE("p: %s, quals: %s, param1: %s, param2: %s, command: %s\n",
wine_dbgstr_w(p), wine_dbgstr_w(quals), wine_dbgstr_w(param1),
wine_dbgstr_w(param2), wine_dbgstr_w(command));

/* Process rest of IF statement which is on the same line
Note: This may process all or some of the cmdList (eg a GOTO) */
WCMD_part_execute(cmdList, command, TRUE, (test != negate));
Expand Down
15 changes: 7 additions & 8 deletions programs/cmd/wcmdmain.c
Original file line number Diff line number Diff line change
Expand Up @@ -1947,26 +1947,25 @@ WCHAR *WCMD_ReadAndParseLine(const WCHAR *optionalcmd, CMD_LIST **output, HANDLE
To be able to handle ('s in the condition part take as much as evaluate_if_condition
would take and skip parsing it here. */
} else if (WCMD_keyword_ws_found(ifCmd, ARRAY_SIZE(ifCmd), curPos)) {
static const WCHAR parmI[] = {'/','I','\0'};
static const WCHAR notW[] = {'n','o','t','\0'};
int negate; /* Negate condition */
int test; /* Condition evaluation result */
WCHAR *p, *command;

inIf = TRUE;

p = curPos+(ARRAY_SIZE(ifCmd));
while (*p == ' ' || *p == '\t') {
while (*p == ' ' || *p == '\t')
p++;
if (lstrcmpiW(WCMD_parameter(p, 0, NULL, TRUE, FALSE), notW) == 0)
p += lstrlenW(notW);
if (lstrcmpiW(WCMD_parameter(p, 0, NULL, TRUE, FALSE), parmI) == 0)
p += lstrlenW(parmI);
}
WCMD_parse (p, quals, param1, param2);

/* Function evaluate_if_condition relies on the global variables quals, param1 and param2
set in a call to WCMD_parse before */
if (evaluate_if_condition(p, &command, &test, &negate) != -1)
{
int if_condition_len = command - curPos;
WINE_TRACE("p: %s, quals: %s, param1: %s, param2: %s, command: %s, if_condition_len: %d\n",
wine_dbgstr_w(p), wine_dbgstr_w(quals), wine_dbgstr_w(param1),
wine_dbgstr_w(param2), wine_dbgstr_w(command), if_condition_len);
memcpy(&curCopyTo[*curLen], curPos, if_condition_len*sizeof(WCHAR));
(*curLen)+=if_condition_len;
curPos+=if_condition_len;
Expand Down

0 comments on commit b1e91a3

Please sign in to comment.