Skip to content

Commit d19af9b

Browse files
Fix #12565, #12566 Fuzzing crash/timeout (cppcheck-opensource#6222)
1 parent 8d2c386 commit d19af9b

6 files changed

Lines changed: 12 additions & 8 deletions

File tree

lib/tokenize.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8613,9 +8613,11 @@ void Tokenizer::findGarbageCode() const
86138613
syntaxError(tok);
86148614
if (Token::Match(tok, "%assign% typename|class %assign%"))
86158615
syntaxError(tok);
8616+
if (Token::Match(tok, "%assign% [;)}]") && (!isCPP() || !Token::Match(tok->previous(), "operator %assign% ;")))
8617+
syntaxError(tok);
86168618
if (Token::Match(tok, "%cop%|=|,|[ %or%|%oror%|/|%"))
86178619
syntaxError(tok);
8618-
if (Token::Match(tok, ";|(|[ %comp%"))
8620+
if (Token::Match(tok, "[;([{] %comp%|&&|%oror%|%or%|%|/"))
86198621
syntaxError(tok);
86208622
if (Token::Match(tok, "%cop%|= ]") && !(isCPP() && Token::Match(tok->previous(), "%type%|[|,|%num% &|=|> ]")))
86218623
syntaxError(tok);
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
assert({:=;})
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
i f(n*a){n b=0;*a=b;%*a=b;--------------------b}

test/testgarbage.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1636,7 +1636,7 @@ class TestGarbage : public TestFixture {
16361636
}
16371637

16381638
void garbageCode203() { // #8972
1639-
checkCode("{ > () {} }");
1639+
ASSERT_THROW(checkCode("{ > () {} }"), InternalError);
16401640
checkCode("template <> a > ::b();");
16411641
}
16421642

test/testtoken.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -743,20 +743,20 @@ class TestToken : public TestFixture {
743743
ASSERT_EQUALS(true, Token::Match(negative.front(), "%bool%"));
744744
}
745745

746-
void matchOr() {
746+
void matchOr() const {
747747
const SimpleTokenList bitwiseOr(";|;");
748748
// cppcheck-suppress simplePatternError - this is intentional
749749
ASSERT_EQUALS(true, Token::Match(bitwiseOr.front(), "; %or%"));
750750
ASSERT_EQUALS(true, Token::Match(bitwiseOr.front(), "; %op%"));
751751
// cppcheck-suppress simplePatternError - this is intentional
752752
ASSERT_EQUALS(false, Token::Match(bitwiseOr.front(), "; %oror%"));
753753

754-
const SimpleTokenizer bitwiseOrAssignment(*this, ";|=;");
754+
const SimpleTokenList bitwiseOrAssignment(";|=;");
755755
// cppcheck-suppress simplePatternError - this is intentional
756-
ASSERT_EQUALS(false, Token::Match(bitwiseOrAssignment.tokens(), "; %or%"));
757-
ASSERT_EQUALS(true, Token::Match(bitwiseOrAssignment.tokens(), "; %op%"));
756+
ASSERT_EQUALS(false, Token::Match(bitwiseOrAssignment.front(), "; %or%"));
757+
ASSERT_EQUALS(true, Token::Match(bitwiseOrAssignment.front(), "; %op%"));
758758
// cppcheck-suppress simplePatternError - this is intentional
759-
ASSERT_EQUALS(false, Token::Match(bitwiseOrAssignment.tokens(), "; %oror%"));
759+
ASSERT_EQUALS(false, Token::Match(bitwiseOrAssignment.front(), "; %oror%"));
760760

761761
const SimpleTokenList logicalOr(";||;");
762762
// cppcheck-suppress simplePatternError - this is intentional

test/testtokenize.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7539,7 +7539,7 @@ class TestTokenizer : public TestFixture {
75397539
void noCrash1() {
75407540
ASSERT_NO_THROW(tokenizeAndStringify(
75417541
"struct A {\n"
7542-
" A( const std::string &name = " " );\n"
7542+
" A( const std::string &name = \" \" );\n"
75437543
"};\n"
75447544
"A::A( const std::string &name ) { return; }\n"));
75457545
}

0 commit comments

Comments
 (0)