From 23fcf6276a59f35d8e2eded2b57e998e0c803a05 Mon Sep 17 00:00:00 2001 From: keinflue <> Date: Thu, 6 May 2021 05:35:28 +0000 Subject: [PATCH] Increase max AST depth and throw error if exceeded --- lib/tokenlist.cpp | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/tokenlist.cpp b/lib/tokenlist.cpp index a3eab7714b5..073c7d04f0c 100644 --- a/lib/tokenlist.cpp +++ b/lib/tokenlist.cpp @@ -35,7 +35,7 @@ // How many compileExpression recursions are allowed? // For practical code this could be endless. But in some special torture test // there needs to be a limit. -static const int AST_MAX_DEPTH = 50; +static const int AST_MAX_DEPTH = 100; TokenList::TokenList(const Settings* settings) : @@ -705,7 +705,9 @@ static void compileUnaryOp(Token *&tok, AST_state& state, void(*f)(Token *&tok, if (f) { tok = tok->next(); state.depth++; - if (tok && state.depth <= AST_MAX_DEPTH) + if (state.depth > AST_MAX_DEPTH) + throw InternalError(tok, "maximum AST depth exceeded", InternalError::AST); + if (tok) f(tok, state); state.depth--; } @@ -1313,7 +1315,7 @@ static void compileComma(Token *&tok, AST_state& state) static void compileExpression(Token *&tok, AST_state& state) { if (state.depth > AST_MAX_DEPTH) - return; // ticket #5592 + throw InternalError(tok, "maximum AST depth exceeded", InternalError::AST); // ticket #5592 if (tok) compileComma(tok, state); }