Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #12790-93 fuzzing crashes #6460

Merged
merged 11 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions lib/templatesimplifier.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,8 @@ void TemplateSimplifier::getTemplateInstantiations()
} else if (Token::Match(tok->previous(), "(|{|}|;|=|>|<<|:|.|*|&|return|<|,|!|[ %name% ::|<|(") ||
Token::Match(tok->previous(), "%type% %name% ::|<") ||
Token::Match(tok->tokAt(-2), "[,:] private|protected|public %name% ::|<")) {
if (!tok->scopeInfo())
syntaxError(tok);
std::string scopeName = tok->scopeInfo()->name;
std::string qualification;
Token * qualificationTok = tok;
Expand Down
22 changes: 12 additions & 10 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8708,7 +8708,8 @@ void Tokenizer::findGarbageCode() const
syntaxError(tok);
if (Token::Match(tok, "typedef [,;:]"))
syntaxError(tok);
if (Token::Match(tok, "! %comp%"))
if (Token::Match(tok, "!|~ %comp%") &&
!(isCPP() && tok->strAt(1) == ">" && Token::simpleMatch(tok->tokAt(-1), "operator")))
syntaxError(tok);
if (Token::Match(tok, "] %name%") && (!isCPP() || !(tok->tokAt(-1) && Token::simpleMatch(tok->tokAt(-2), "delete [")))) {
if (tok->next()->isUpperCaseName())
Expand Down Expand Up @@ -8784,24 +8785,25 @@ void Tokenizer::findGarbageCode() const
for (const Token *tok = tokens(); tok; tok = tok->next()) {
if (Token::simpleMatch(tok, "< >") && !(Token::Match(tok->tokAt(-1), "%name%") || (tok->tokAt(-1) && Token::Match(tok->tokAt(-2), "operator %op%"))))
syntaxError(tok);
if (Token::simpleMatch(tok, ": template") && !Token::Match(tok->tokAt(-1), "public|private|protected"))
syntaxError(tok);
if (!Token::simpleMatch(tok, "template <"))
continue;
if (!tok->tokAt(2) || tok->tokAt(2)->isLiteral())
syntaxError(tok);
if (tok->previous() && !Token::Match(tok->previous(), ":|;|{|}|)|>|\"C++\"")) {
if (tok->previous() && !Token::Match(tok->previous(), ":|,|;|{|}|)|<|>|\"C++\"")) {
if (tok->previous()->isUpperCaseName())
unknownMacroError(tok->previous());
else
syntaxError(tok);
}
const Token * const tok1 = tok;
tok = tok->next()->findClosingBracket();
if (!tok)
syntaxError(tok1);
if (!Token::Match(tok, ">|>> ::|...| %name%") &&
!Token::Match(tok, ">|>> [ [ %name%") &&
!Token::Match(tok, "> >|*"))
syntaxError(tok->next() ? tok->next() : tok1);
const Token * const tok1 = tok->next()->findClosingBracket();
if (!tok1)
syntaxError(tok);
if (!Token::Match(tok1, ">|>> ::|...| %name%") &&
!Token::Match(tok1, ">|>> [ [ %name%") &&
!Token::Match(tok1, "> >|*"))
syntaxError(tok1->next() ? tok1->next() : tok);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{template<~>tu<0>}tu=c<F
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
t<e<:template<>e=c>n
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
template< <>t=t<>>d
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
template<~>tu<2>tu=<tu<0&tu<0&n
Loading