From 80d10598c1cc4e071651f7d3c3611bed5156ef2f Mon Sep 17 00:00:00 2001 From: frosch Date: Thu, 22 Jun 2017 16:32:50 +0000 Subject: [PATCH] (svn r27884) -Fix: Console command parser failed when the command had many parameters, and also did not print any error messages about it. --- src/console.cpp | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/src/console.cpp b/src/console.cpp index ef62a8f286..ece8599168 100644 --- a/src/console.cpp +++ b/src/console.cpp @@ -434,7 +434,10 @@ void IConsoleCmdExec(const char *cmdstr) * enclosed in "" are taken as one token. We can only go as far as the amount * of characters in our stream or the max amount of tokens we can handle */ for (cmdptr = cmdstr, t_index = 0, tstream_i = 0; *cmdptr != '\0'; cmdptr++) { - if (t_index >= lengthof(tokens) || tstream_i >= lengthof(tokenstream)) break; + if (tstream_i >= lengthof(tokenstream)) { + IConsoleError("command line too long"); + return; + } switch (*cmdptr) { case ' ': // Token separator @@ -452,6 +455,10 @@ void IConsoleCmdExec(const char *cmdstr) case '"': // Tokens enclosed in "" are one token longtoken = !longtoken; if (!foundtoken) { + if (t_index >= lengthof(tokens)) { + IConsoleError("command line too long"); + return; + } tokens[t_index++] = &tokenstream[tstream_i]; foundtoken = true; } @@ -466,6 +473,10 @@ void IConsoleCmdExec(const char *cmdstr) tokenstream[tstream_i++] = *cmdptr; if (!foundtoken) { + if (t_index >= lengthof(tokens)) { + IConsoleError("command line too long"); + return; + } tokens[t_index++] = &tokenstream[tstream_i - 1]; foundtoken = true; }