Skip to content

Commit 22477ef

Browse files
Fix #12790-93 fuzzing crashes (#6460)
1 parent 448b951 commit 22477ef

6 files changed

Lines changed: 18 additions & 10 deletions

lib/templatesimplifier.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -833,6 +833,8 @@ void TemplateSimplifier::getTemplateInstantiations()
833833
} else if (Token::Match(tok->previous(), "(|{|}|;|=|>|<<|:|.|*|&|return|<|,|!|[ %name% ::|<|(") ||
834834
Token::Match(tok->previous(), "%type% %name% ::|<") ||
835835
Token::Match(tok->tokAt(-2), "[,:] private|protected|public %name% ::|<")) {
836+
if (!tok->scopeInfo())
837+
syntaxError(tok);
836838
std::string scopeName = tok->scopeInfo()->name;
837839
std::string qualification;
838840
Token * qualificationTok = tok;

lib/tokenize.cpp

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8708,7 +8708,8 @@ void Tokenizer::findGarbageCode() const
87088708
syntaxError(tok);
87098709
if (Token::Match(tok, "typedef [,;:]"))
87108710
syntaxError(tok);
8711-
if (Token::Match(tok, "! %comp%"))
8711+
if (Token::Match(tok, "!|~ %comp%") &&
8712+
!(isCPP() && tok->strAt(1) == ">" && Token::simpleMatch(tok->tokAt(-1), "operator")))
87128713
syntaxError(tok);
87138714
if (Token::Match(tok, "] %name%") && (!isCPP() || !(tok->tokAt(-1) && Token::simpleMatch(tok->tokAt(-2), "delete [")))) {
87148715
if (tok->next()->isUpperCaseName())
@@ -8784,24 +8785,25 @@ void Tokenizer::findGarbageCode() const
87848785
for (const Token *tok = tokens(); tok; tok = tok->next()) {
87858786
if (Token::simpleMatch(tok, "< >") && !(Token::Match(tok->tokAt(-1), "%name%") || (tok->tokAt(-1) && Token::Match(tok->tokAt(-2), "operator %op%"))))
87868787
syntaxError(tok);
8788+
if (Token::simpleMatch(tok, ": template") && !Token::Match(tok->tokAt(-1), "public|private|protected"))
8789+
syntaxError(tok);
87878790
if (!Token::simpleMatch(tok, "template <"))
87888791
continue;
87898792
if (!tok->tokAt(2) || tok->tokAt(2)->isLiteral())
87908793
syntaxError(tok);
8791-
if (tok->previous() && !Token::Match(tok->previous(), ":|;|{|}|)|>|\"C++\"")) {
8794+
if (tok->previous() && !Token::Match(tok->previous(), ":|,|;|{|}|)|<|>|\"C++\"")) {
87928795
if (tok->previous()->isUpperCaseName())
87938796
unknownMacroError(tok->previous());
87948797
else
87958798
syntaxError(tok);
87968799
}
8797-
const Token * const tok1 = tok;
8798-
tok = tok->next()->findClosingBracket();
8799-
if (!tok)
8800-
syntaxError(tok1);
8801-
if (!Token::Match(tok, ">|>> ::|...| %name%") &&
8802-
!Token::Match(tok, ">|>> [ [ %name%") &&
8803-
!Token::Match(tok, "> >|*"))
8804-
syntaxError(tok->next() ? tok->next() : tok1);
8800+
const Token * const tok1 = tok->next()->findClosingBracket();
8801+
if (!tok1)
8802+
syntaxError(tok);
8803+
if (!Token::Match(tok1, ">|>> ::|...| %name%") &&
8804+
!Token::Match(tok1, ">|>> [ [ %name%") &&
8805+
!Token::Match(tok1, "> >|*"))
8806+
syntaxError(tok1->next() ? tok1->next() : tok);
88058807
}
88068808
}
88078809

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{template<~>tu<0>}tu=c<F
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
t<e<:template<>e=c>n
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
template< <>t=t<>>d
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
template<~>tu<2>tu=<tu<0&tu<0&n

0 commit comments

Comments
 (0)