Skip to content

Commit ef36148

Browse files
Fix #12510 fuzzing crash in SymbolDatabase::setValueTypeInTokenList() (#6161)
1 parent 23ec401 commit ef36148

3 files changed

Lines changed: 10 additions & 3 deletions

File tree

lib/symboldatabase.cpp

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2558,11 +2558,11 @@ Function::Function(const Token *tok,
25582558
}
25592559

25602560
// class constructor/destructor
2561-
else if (((tokenDef->str() == scope->className) ||
2561+
else if (scope->isClassOrStructOrUnion() &&
2562+
((tokenDef->str() == scope->className) ||
25622563
(tokenDef->str().substr(0, scope->className.size()) == scope->className &&
25632564
tokenDef->str().size() > scope->className.size() + 1 &&
2564-
tokenDef->str()[scope->className.size() + 1] == '<')) &&
2565-
scope->type != Scope::ScopeType::eNamespace) {
2565+
tokenDef->str()[scope->className.size() + 1] == '<'))) {
25662566
// destructor
25672567
if (tokenDef->previous()->str() == "~")
25682568
type = Function::eDestructor;
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
o oo(){extern oo();}

test/testsymboldatabase.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2239,6 +2239,12 @@ class TestSymbolDatabase : public TestFixture {
22392239
ASSERT(db && ctor && ctor->type == Function::eMoveConstructor);
22402240
ASSERT(ctor && ctor->retDef == nullptr);
22412241
}
2242+
{
2243+
GET_SYMBOL_DB("void f() { extern void f(); }");
2244+
ASSERT(db && db->scopeList.size() == 2);
2245+
const Function* f = findFunctionByName("f", &db->scopeList.back());
2246+
ASSERT(f && f->type == Function::eFunction);
2247+
}
22422248
}
22432249

22442250
void functionDeclarationTemplate() {

0 commit comments

Comments
 (0)