https://git.reactos.org/?p=reactos.git;a=commitdiff;h=c81bf4f823aa09448a583…
commit c81bf4f823aa09448a58331b5c3e38f88416c208
Author: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
AuthorDate: Thu Sep 3 16:03:18 2020 +0200
Commit: Hermès Bélusca-Maïto <hermes.belusca-maito(a)reactos.org>
CommitDate: Thu Sep 3 16:05:55 2020 +0200
[CMD] IF: Add extra validity checks in ExecuteIf().
---
base/shell/cmd/cmd.c | 2 +-
base/shell/cmd/if.c | 27 +++++++++++++++++++--------
2 files changed, 20 insertions(+), 9 deletions(-)
diff --git a/base/shell/cmd/cmd.c b/base/shell/cmd/cmd.c
index fbc12154d1b..f760bf7745c 100644
--- a/base/shell/cmd/cmd.c
+++ b/base/shell/cmd/cmd.c
@@ -938,7 +938,7 @@ GetEnvVarOrSpecial(LPCTSTR varName)
/* %CMDEXTVERSION% */
else if (_tcsicmp(varName, _T("CMDEXTVERSION")) == 0)
{
- /* Set version number to CMDEXTVERSION */
+ /* Set Command Extensions version number to CMDEXTVERSION */
_itot(CMDEXTVERSION, ret, 10);
return ret;
}
diff --git a/base/shell/cmd/if.c b/base/shell/cmd/if.c
index e74298ad612..66526ee154a 100644
--- a/base/shell/cmd/if.c
+++ b/base/shell/cmd/if.c
@@ -78,20 +78,19 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
Right = DoDelayedExpansion(Cmd->If.RightArg);
if (!Right)
{
- cmd_free(Left);
+ if (Left) cmd_free(Left);
return 1;
}
if (bEnableExtensions && (Cmd->If.Operator == IF_CMDEXTVERSION))
{
- /* IF CMDEXTVERSION n: check if Command Extensions version
- * is greater or equal to n */
+ /* IF CMDEXTVERSION n: check if Command Extensions
+ * version is greater or equal to n. */
DWORD n = _tcstoul(Right, ¶m, 10);
if (*param != _T('\0'))
{
error_syntax(Right);
- cmd_free(Right);
- return 1;
+ goto fail;
}
result = (CMDEXTVERSION >= n);
}
@@ -107,8 +106,7 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
if (*param != _T('\0'))
{
error_syntax(Right);
- cmd_free(Right);
- return 1;
+ goto fail;
}
result = (nErrorLevel >= n);
}
@@ -178,11 +176,19 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
case IF_LEQ: result = (result <= 0); break;
case IF_GTR: result = (result > 0); break;
case IF_GEQ: result = (result >= 0); break;
+ default: goto unknownOp;
}
}
+ else
+ {
+unknownOp:
+ ERR("Unknown IF operator 0x%x\n", Cmd->If.Operator);
+ ASSERT(FALSE);
+ goto fail;
+ }
}
- cmd_free(Left);
+ if (Left) cmd_free(Left);
cmd_free(Right);
if (result ^ ((Cmd->If.Flags & IFFLAG_NEGATE) != 0))
@@ -195,6 +201,11 @@ INT ExecuteIf(PARSED_COMMAND *Cmd)
/* Full condition was false, do the "else" command if there is one */
return ExecuteCommand(Cmd->Subcommands->Next);
}
+
+fail:
+ if (Left) cmd_free(Left);
+ cmd_free(Right);
+ return 1;
}
/* EOF */