diff options
| author | Christian Kandeler <christian.kandeler@qt.io> | 2023-02-07 14:32:25 +0100 |
|---|---|---|
| committer | Christian Kandeler <christian.kandeler@qt.io> | 2023-02-08 12:53:31 +0000 |
| commit | bd2ca236e11b25ae28e8f519258627f66a34ddfd (patch) | |
| tree | 0d4c812cc04bac47621660e24d9c46b696319cd6 /src/libs/cplusplus | |
| parent | 06b579a75be7924462a3cdfe9ecb8e60b3e01524 (diff) | |
| download | qt-creator-bd2ca236e11b25ae28e8f519258627f66a34ddfd.tar.gz | |
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>
Diffstat (limited to 'src/libs/cplusplus')
| -rw-r--r-- | src/libs/cplusplus/pp-engine.cpp | 10 | ||||
| -rw-r--r-- | src/libs/cplusplus/pp-engine.h | 3 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp index 50cd1241de..de18711233 100644 --- a/src/libs/cplusplus/pp-engine.cpp +++ b/src/libs/cplusplus/pp-engine.cpp @@ -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); diff --git a/src/libs/cplusplus/pp-engine.h b/src/libs/cplusplus/pp-engine.h index 49cdab2b82..c888e8775d 100644 --- a/src/libs/cplusplus/pp-engine.h +++ b/src/libs/cplusplus/pp-engine.h @@ -29,6 +29,8 @@ #include <cplusplus/Lexer.h> #include <cplusplus/Token.h> +#include <utils/guard.h> + #include <QVector> #include <QBitArray> #include <QByteArray> @@ -241,6 +243,7 @@ private: Environment *m_env; QByteArray m_scratchBuffer; CancelChecker m_cancelChecker; + Utils::Guard m_includeDepthGuard; bool m_expandFunctionlikeMacros; bool m_keepComments; |
