forked from qt-creator/qt-creator
		
	CPlusPlus: Check maximum include depth in lexer
We use a value of 200, which is also GCC's default. Fixes: QTCREATORBUG-28770 Change-Id: Id02b324cd2ffa81a709441a5d93856bcd06501c3 Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
		| @@ -57,6 +57,7 @@ using namespace Utils; | ||||
| namespace { | ||||
| enum { | ||||
|     MAX_FUNCTION_LIKE_ARGUMENTS_COUNT = 100, | ||||
|     MAX_INCLUDE_DEPTH = 200, | ||||
|     MAX_TOKEN_EXPANSION_COUNT = 5000, | ||||
|     MAX_TOKEN_BUFFER_DEPTH = 16000 // for when macros are using some kind of right-folding, this is the list of "delayed" buffers waiting to be expanded after the current one. | ||||
| }; | ||||
| @@ -1677,6 +1678,15 @@ void Preprocessor::handleIncludeDirective(PPToken *tk, bool includeNext) | ||||
|     if (m_cancelChecker && m_cancelChecker()) | ||||
|         return; | ||||
|  | ||||
|     GuardLocker depthLocker(m_includeDepthGuard); | ||||
|     if (m_includeDepthGuard.lockCount() > MAX_INCLUDE_DEPTH) { | ||||
|         // FIXME: Categorized logging! | ||||
| #ifndef NO_DEBUG | ||||
|         std::cerr << "Maximum include depth exceeded" << m_state.m_currentFileName << std::endl; | ||||
| #endif | ||||
|         return; | ||||
|     } | ||||
|  | ||||
|     m_state.m_lexer->setScanAngleStringLiteralTokens(true); | ||||
|     lex(tk); // consume "include" token | ||||
|     m_state.m_lexer->setScanAngleStringLiteralTokens(false); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user