Skip to content

Commit d49fd82

Browse files
authored
fixed fuzzing crashes (#6089)
1 parent ed64e97 commit d49fd82

7 files changed

Lines changed: 10 additions & 3 deletions

lib/checksizeof.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,8 @@ void CheckSizeof::checkSizeofForPointerSize()
236236
continue;
237237

238238
// Now check for the sizeof usage: Does the level of pointer indirection match?
239-
if (tokSize->linkAt(1)->strAt(-1) == "*") {
239+
const Token * const tokLink = tokSize->linkAt(1);
240+
if (tokLink && tokLink->strAt(-1) == "*") {
240241
if (variable && variable->valueType() && variable->valueType()->pointer == 1 && variable->valueType()->type != ValueType::VOID)
241242
sizeofForPointerError(variable, variable->str());
242243
else if (variable2 && variable2->valueType() && variable2->valueType()->pointer == 1 && variable2->valueType()->type != ValueType::VOID)

lib/tokenize.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1940,7 +1940,7 @@ void Tokenizer::simplifyTypedefCpp()
19401940

19411941
// start substituting at the typedef name by replacing it with the type
19421942
Token* replStart = tok2; // track first replaced token
1943-
for (Token* tok3 = typeStart; tok3->str() != ";"; tok3 = tok3->next())
1943+
for (Token* tok3 = typeStart; tok3 && (tok3->str() != ";"); tok3 = tok3->next())
19441944
tok3->isSimplifiedTypedef(true);
19451945
if (isPointerTypeCall) {
19461946
tok2->deleteThis();
@@ -10537,6 +10537,8 @@ void Tokenizer::simplifyNamespaceAliases()
1053710537

1053810538
int endScope = scope;
1053910539
Token * tokLast = tokNameEnd->next();
10540+
if (!tokLast)
10541+
return;
1054010542
Token * tokNext = tokLast->next();
1054110543
Token * tok2 = tokNext;
1054210544

lib/tokenlist.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1582,7 +1582,7 @@ static Token * createAstAtToken(Token *tok)
15821582
AST_state state1(cpp);
15831583
compileExpression(tok2, state1);
15841584
if (Token::Match(init1, "( !!{")) {
1585-
for (Token *tok3 = init1; tok3 != tok3->link(); tok3 = tok3->next()) {
1585+
for (Token *tok3 = init1; tok3 && tok3 != tok3->link(); tok3 = tok3->next()) {
15861586
if (tok3->astParent()) {
15871587
while (tok3->astParent())
15881588
tok3 = tok3->astParent();
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
a,typedef U typedef,U,i
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
namespace d=S
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
{for(()s)}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
o k(){t*data;{memcpy(data,,sizeof\)}}

0 commit comments

Comments
 (0)