From 51b64191e569dd345bf38d3d981fcb28cea8e1f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Daniel=20Marjam=C3=A4ki?= Date: Sat, 30 Mar 2019 14:22:24 +0100 Subject: [PATCH] Fixed slow checking in FwdAnalysis Credit to OSS-Fuzz for reporting this! --- lib/astutils.cpp | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/lib/astutils.cpp b/lib/astutils.cpp index a05104e8d..428761696 100644 --- a/lib/astutils.cpp +++ b/lib/astutils.cpp @@ -1388,11 +1388,14 @@ FwdAnalysis::Result FwdAnalysis::check(const Token *expr, const Token *startToke // all variable ids in expr. std::set exprVarIds; bool local = true; + bool unknownVarId = false; visitAstNodes(expr, [&](const Token *tok) { - if (tok->varId() == 0 && tok->isName() && tok->previous()->str() != ".") - // unknown variables are not local - local = false; + if (tok->varId() == 0 && tok->isName() && tok->previous()->str() != ".") { + // unknown variable + unknownVarId = true; + return ChildrenToVisit::none; + } if (tok->varId() > 0) { exprVarIds.insert(tok->varId()); if (!Token::simpleMatch(tok->previous(), ".")) { @@ -1406,6 +1409,9 @@ FwdAnalysis::Result FwdAnalysis::check(const Token *expr, const Token *startToke return ChildrenToVisit::op1_and_op2; }); + if (unknownVarId) + return Result(FwdAnalysis::Result::Type::BAILOUT); + // In unused values checking we do not want to check assignments to // global data. if (mWhat == What::UnusedValue && isGlobalData(expr))