aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorOrgad Shaneh <orgad.shaneh@audiocodes.com>2015-02-03 09:10:37 +0200
committerNikolai Kosjar <nikolai.kosjar@theqtcompany.com>2015-02-03 12:03:29 +0000
commit75a943ef57da0179e742c7d396fb28f909e1add1 (patch)
tree9788b80781437639f94f888b6e0fb6197403c0d8 /src
parentd7e5d41494597ceaf7422f4b6a918d024c31caad (diff)
C++: Fix crash when #if[def] nesting is deeper than 512 levels
Change-Id: I5e86da3a36514545834f554470b147ad8be43344 Reviewed-by: Eike Ziller <eike.ziller@theqtcompany.com> Reviewed-by: Nikolai Kosjar <nikolai.kosjar@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r--src/libs/cplusplus/pp-engine.cpp27
1 files changed, 22 insertions, 5 deletions
diff --git a/src/libs/cplusplus/pp-engine.cpp b/src/libs/cplusplus/pp-engine.cpp
index c0e6e3e827a..9cafea26f2d 100644
--- a/src/libs/cplusplus/pp-engine.cpp
+++ b/src/libs/cplusplus/pp-engine.cpp
@@ -140,6 +140,12 @@ static bool isQtReservedWord(const char *name, int size)
return false;
}
+static void nestingTooDeep()
+{
+#ifndef NO_DEBUG
+ std::cerr << "*** WARNING #if / #ifdef nesting exceeded the max level " << MAX_LEVEL << std::endl;
+#endif
+}
} // anonymous namespace
@@ -1819,6 +1825,12 @@ void Preprocessor::handleIfDirective(PPToken *tk)
lex(tk); // consume "if" token
Value result;
const PPToken lastExpressionToken = evalExpression(tk, result);
+
+ if (m_state.m_ifLevel >= MAX_LEVEL - 1) {
+ nestingTooDeep();
+ return;
+ }
+
const bool value = !result.is_zero();
const bool wasSkipping = m_state.m_skipping[m_state.m_ifLevel];
@@ -1945,12 +1957,17 @@ void Preprocessor::handleIfDefDirective(bool checkUndefined, PPToken *tk)
value = !value;
const bool wasSkipping = m_state.m_skipping[m_state.m_ifLevel];
- ++m_state.m_ifLevel;
- m_state.m_trueTest[m_state.m_ifLevel] = value;
- m_state.m_skipping[m_state.m_ifLevel] = wasSkipping ? wasSkipping : !value;
- if (m_client && !wasSkipping && !value)
- startSkippingBlocks(*tk);
+ if (m_state.m_ifLevel < MAX_LEVEL - 1) {
+ ++m_state.m_ifLevel;
+ m_state.m_trueTest[m_state.m_ifLevel] = value;
+ m_state.m_skipping[m_state.m_ifLevel] = wasSkipping ? wasSkipping : !value;
+
+ if (m_client && !wasSkipping && !value)
+ startSkippingBlocks(*tk);
+ } else {
+ nestingTooDeep();
+ }
lex(tk); // consume the identifier
#ifndef NO_DEBUG