Skip to content

Commit fec7ab7

Browse files
Fix #13693 fuzzing crash (null-pointer-use) in findEscapeStatement() (danmar#8106)
Co-authored-by: chrchr-github <noreply@github.com>
1 parent ab00a3a commit fec7ab7

File tree

3 files changed

+13
-1
lines changed

3 files changed

+13
-1
lines changed

lib/tokenize.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ static bool isClassStructUnionEnumStart(const Token * tok)
108108
if (!Token::Match(tok->previous(), "class|struct|union|enum|%name%|>|>> {"))
109109
return false;
110110
const Token * tok2 = tok->previous();
111-
while (tok2 && !Token::Match(tok2, "class|struct|union|enum|{|}|;"))
111+
while (tok2 && !Token::Match(tok2, "class|struct|union|enum|{|}|)|;|>|>>"))
112112
tok2 = tok2->previous();
113113
return Token::Match(tok2, "class|struct|union|enum");
114114
}
@@ -8782,6 +8782,16 @@ void Tokenizer::findGarbageCode() const
87828782
else if (tok->isKeyword() && nonGlobalKeywords.count(tok->str()) && !Token::Match(tok->tokAt(-2), "operator %str%"))
87838783
syntaxError(tok, "keyword '" + tok->str() + "' is not allowed in global scope");
87848784
}
8785+
for (const Token *tok = tokens(); tok; tok = tok->next()) {
8786+
if (tok->str() == "{" && isClassStructUnionEnumStart(tok)) {
8787+
for (const Token* tok2 = tok->next(); tok2 != tok->link(); tok2 = tok2->next()) {
8788+
if (tok2->str() == "{")
8789+
tok2 = tok2->link();
8790+
else if (tok2->isKeyword() && nonGlobalKeywords.count(tok2->str()) && !Token::Match(tok2->tokAt(-2), "operator %str%"))
8791+
syntaxError(tok2, "keyword '" + tok2->str() + "' is not allowed in class/struct/union/enum scope");
8792+
}
8793+
}
8794+
}
87858795

87868796
// case keyword must be inside switch
87878797
for (const Token *tok = tokens(); tok; tok = tok->next()) {
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
(c*8s){}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
v(){union{a i;for(i=0;!i;);};}

0 commit comments

Comments
 (0)