From b4a3dd10e12d4dc74780bbc360289f806e8152d9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89milie=20Feral?= Date: Tue, 28 Jul 2020 16:30:04 +0200 Subject: [PATCH] [apps/shared] ToolBoxHelpers: don't overflow buffer If the commandLength is > than the buffer size, we have to escape at some point to avoid overflowing the buffer. --- apps/shared/toolbox_helpers.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/shared/toolbox_helpers.cpp b/apps/shared/toolbox_helpers.cpp index 8758ca763..fc16a0544 100644 --- a/apps/shared/toolbox_helpers.cpp +++ b/apps/shared/toolbox_helpers.cpp @@ -41,7 +41,7 @@ void TextToInsertForCommandText(const char * command, int commandLength, char * UTF8Decoder decoder(command); CodePoint codePoint = decoder.nextCodePoint(); - while (codePoint != UCodePointNull && (commandLength < 0 || (decoder.stringPosition() - command <= commandLength))) { + while (codePoint != UCodePointNull && index < bufferSize - 1 && (commandLength < 0 || (decoder.stringPosition() - command <= commandLength))) { if (codePoint == ')') { numberOfOpenParentheses--; } else if (codePoint == ']') {