From 63eac64da512d324f3f4a448dc9552b5b4be8c6b Mon Sep 17 00:00:00 2001 From: chrchr-github <78114321+chrchr-github@users.noreply.github.com> Date: Wed, 20 Mar 2024 12:28:23 +0100 Subject: [PATCH] Fix #12512 fuzzing timeout in compileExpression() (#6160) --- lib/tokenlist.cpp | 5 ++++- .../timeout-0ee5eed9abd34e9d23640a5b82dd724affd05b79 | 1 + 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 test/cli/fuzz-timeout/timeout-0ee5eed9abd34e9d23640a5b82dd724affd05b79 diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index 5e9017eb487..af8d20e17d8 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -1758,7 +1758,10 @@ static Token * createAstAtToken(Token *tok) void TokenList::createAst() const { for (Token *tok = mTokensFrontBack.front; tok; tok = tok ? tok->next() : nullptr) { - tok = createAstAtToken(tok); + Token* const nextTok = createAstAtToken(tok); + if (precedes(nextTok, tok)) + throw InternalError(tok, "Syntax Error: Infinite loop when creating AST.", InternalError::AST); + tok = nextTok; } } diff --git a/test/cli/fuzz-timeout/timeout-0ee5eed9abd34e9d23640a5b82dd724affd05b79 b/test/cli/fuzz-timeout/timeout-0ee5eed9abd34e9d23640a5b82dd724affd05b79 new file mode 100644 index 00000000000..5f9465da55e --- /dev/null +++ b/test/cli/fuzz-timeout/timeout-0ee5eed9abd34e9d23640a5b82dd724affd05b79 @@ -0,0 +1 @@ +;new t() \ No newline at end of file