Skip to content

Commit

Permalink
Fix #12643-46 fuzzing crashes (danmar#6336)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrchr-github committed Apr 24, 2024
1 parent 7dab204 commit 9fab9b9
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 3 deletions.
6 changes: 6 additions & 0 deletions lib/tokenize.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8690,6 +8690,12 @@ void Tokenizer::findGarbageCode() const
syntaxError(tok);
if (Token::Match(tok, "^ %op%") && !Token::Match(tok->next(), "[>*+-!~]"))
syntaxError(tok);
if (Token::Match(tok, ": [)]=]"))
syntaxError(tok);
if (Token::Match(tok, "typedef [,;]"))
syntaxError(tok);
if (Token::Match(tok, "! %comp%"))
syntaxError(tok);

if (tok->link() && Token::Match(tok, "[([]") && (!tok->tokAt(-1) || !tok->tokAt(-1)->isControlFlowKeyword())) {
const Token* const end = tok->link();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
assert({:=4;})
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
v o(i a){$ i;for(i:)a=[]0;}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
n a(){!!=!!?:b}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{for(typedef,typedef;);}
6 changes: 3 additions & 3 deletions test/testgarbage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -862,7 +862,7 @@ class TestGarbage : public TestFixture {
ASSERT_THROW_INTERNAL_EQUALS(checkCode("{ xs :: i(:) ! ! x/5 ! !\n"
"i, :: a :: b integer, } foo2(x) :: j(:)\n"
"b type(*), d(:), a x :: end d(..), foo end\n"
"foo4 b d(..), a a x type(*), b foo2 b"), INTERNAL, "Internal error. AST cyclic dependency.");
"foo4 b d(..), a a x type(*), b foo2 b"), SYNTAX, "syntax error");
}

void garbageCode100() { // #6840
Expand Down Expand Up @@ -987,7 +987,7 @@ class TestGarbage : public TestFixture {
}

void garbageCode125() {
ASSERT_THROW_INTERNAL(checkCode("{ T struct B : T valueA_AA ; } T : [ T > ( ) { B } template < T > struct A < > : ] { ( ) { return valueA_AC struct { : } } b A < int > AC ( ) a_aa.M ; ( ) ( ) }"), UNKNOWN_MACRO);
ASSERT_THROW_INTERNAL(checkCode("{ T struct B : T valueA_AA ; } T : [ T > ( ) { B } template < T > struct A < > : ] { ( ) { return valueA_AC struct { : } } b A < int > AC ( ) a_aa.M ; ( ) ( ) }"), SYNTAX);
ASSERT_THROW_INTERNAL(checkCode("template < Types > struct S :{ ( S < ) S >} { ( ) { } } ( ) { return S < void > ( ) }"),
SYNTAX);
}
Expand Down Expand Up @@ -1661,7 +1661,7 @@ class TestGarbage : public TestFixture {

void garbageCode206() {
ASSERT_EQUALS("[test.cpp:1] syntax error: operator", getSyntaxError("void foo() { for (auto operator new : int); }"));
ASSERT_EQUALS("[test.cpp:1] syntax error: operator", getSyntaxError("void foo() { for (a operator== :) }"));
ASSERT_EQUALS("[test.cpp:1] syntax error", getSyntaxError("void foo() { for (a operator== :) }"));
}

void garbageCode207() { // #8750
Expand Down

0 comments on commit 9fab9b9

Please sign in to comment.