Skip to content

Commit 9e87bb1

Browse files
committed
Fix #13693 fuzzing crash (null-pointer-use) in findEscapeStatement()
1 parent dd01ff1 commit 9e87bb1

2 files changed

Lines changed: 12 additions & 1 deletion

File tree

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
}
@@ -8776,6 +8776,16 @@ void Tokenizer::findGarbageCode() const
87768776
else if (tok->isKeyword() && nonGlobalKeywords.count(tok->str()) && !Token::Match(tok->tokAt(-2), "operator %str%"))
87778777
syntaxError(tok, "keyword '" + tok->str() + "' is not allowed in global scope");
87788778
}
8779+
for (const Token *tok = tokens(); tok; tok = tok->next()) {
8780+
if (tok->str() == "{" && isClassStructUnionEnumStart(tok)) {
8781+
for (const Token* tok2 = tok->next(); tok2 != tok->link(); tok2 = tok2->next()) {
8782+
if (tok2->str() == "{")
8783+
tok2 = tok2->link();
8784+
else if (tok2->isKeyword() && nonGlobalKeywords.count(tok2->str()) && !Token::Match(tok2->tokAt(-2), "operator %str%"))
8785+
syntaxError(tok2, "keyword '" + tok2->str() + "' is not allowed in class/struct/union scope");
8786+
}
8787+
}
8788+
}
87798789

87808790
// case keyword must be inside switch
87818791
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+
v(){union{a i;for(i=0;!i;);};}

0 commit comments

Comments
 (0)