forked from qt-creator/qt-creator
Fixed stack-overflow when parsing insanely nested compound statements.
Thanks to Clang's parser_overflow.cpp which has >16000 nested compound statements to check exactly the same. Change-Id: I2b604f8ceb01115d7fe950994e0677a081e99481 Reviewed-by: Christian Kamm <christian.d.kamm@nokia.com>
This commit is contained in:
9
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
9
src/libs/3rdparty/cplusplus/Parser.cpp
vendored
@@ -37,6 +37,7 @@
|
||||
|
||||
#define CPLUSPLUS_NO_DEBUG_RULE
|
||||
#define MAX_EXPRESSION_DEPTH 100
|
||||
#define MAX_STATEMENT_DEPTH 100
|
||||
|
||||
using namespace CPlusPlus;
|
||||
|
||||
@@ -181,7 +182,8 @@ Parser::Parser(TranslationUnit *unit)
|
||||
_inFunctionBody(false),
|
||||
_inObjCImplementationContext(false),
|
||||
_inExpressionStatement(false),
|
||||
_expressionDepth(0)
|
||||
_expressionDepth(0),
|
||||
_statementDepth(0)
|
||||
{ }
|
||||
|
||||
Parser::~Parser()
|
||||
@@ -3209,6 +3211,10 @@ bool Parser::parseCompoundStatement(StatementAST *&node)
|
||||
{
|
||||
DEBUG_THIS_RULE();
|
||||
if (LA() == T_LBRACE) {
|
||||
if (_statementDepth > MAX_STATEMENT_DEPTH)
|
||||
return false;
|
||||
++_statementDepth;
|
||||
|
||||
CompoundStatementAST *ast = new (_pool) CompoundStatementAST;
|
||||
ast->lbrace_token = consumeToken();
|
||||
|
||||
@@ -3233,6 +3239,7 @@ bool Parser::parseCompoundStatement(StatementAST *&node)
|
||||
}
|
||||
match(T_RBRACE, &ast->rbrace_token);
|
||||
node = ast;
|
||||
--_statementDepth;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
1
src/libs/3rdparty/cplusplus/Parser.h
vendored
1
src/libs/3rdparty/cplusplus/Parser.h
vendored
@@ -315,6 +315,7 @@ private:
|
||||
bool _inObjCImplementationContext: 1;
|
||||
bool _inExpressionStatement: 1;
|
||||
int _expressionDepth;
|
||||
int _statementDepth;
|
||||
|
||||
MemoryPool _expressionStatementTempPool;
|
||||
std::map<unsigned, TemplateArgumentListEntry> _templateArgumentList;
|
||||
|
Reference in New Issue
Block a user