Skip to content

Commit ffd5a09

Browse files
committed
Added guard to prevent stack overflow in hasNonReferenceSuperClass()
1 parent b3f8660 commit ffd5a09

File tree

1 file changed

+19
-9
lines changed

1 file changed

+19
-9
lines changed

src/classdef.cpp

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3200,28 +3200,30 @@ void ClassDefImpl::setTemplateArguments(const ArgumentList &al)
32003200
m_impl->tempArgs = al;
32013201
}
32023202

3203-
/*! Returns \c TRUE iff this class or a class inheriting from this class
3204-
* is \e not defined in an external tag file.
3205-
*/
3206-
bool ClassDefImpl::hasNonReferenceSuperClass() const
3203+
static bool hasNonReferenceSuperClassRec(const ClassDef *cd,int level)
32073204
{
3208-
bool found=!isReference() && isLinkableInProject() && !isHidden();
3205+
bool found=!cd->isReference() && cd->isLinkableInProject() && !cd->isHidden();
32093206
if (found)
32103207
{
32113208
return TRUE; // we're done if this class is not a reference
32123209
}
3213-
for (const auto &ibcd : m_impl->inheritedBy)
3210+
for (const auto &ibcd : cd->subClasses())
32143211
{
3215-
ClassDef *bcd=ibcd.classDef;
3212+
const ClassDef *bcd=ibcd.classDef;
3213+
if (level>256)
3214+
{
3215+
err("Possible recursive class relation while inside %s and looking for base class %s\n",qPrint(cd->name()),qPrint(bcd->name()));
3216+
return FALSE;
3217+
}
32163218
// recurse into the super class branch
3217-
found = found || bcd->hasNonReferenceSuperClass();
3219+
found = found || hasNonReferenceSuperClassRec(bcd,level+1);
32183220
if (!found)
32193221
{
32203222
// look for template instances that might have non-reference super classes
32213223
for (const auto &cil : bcd->getTemplateInstances())
32223224
{
32233225
// recurse into the template instance branch
3224-
found = cil.classDef->hasNonReferenceSuperClass();
3226+
found = hasNonReferenceSuperClassRec(cil.classDef,level+1);
32253227
if (found) break;
32263228
}
32273229
}
@@ -3231,6 +3233,14 @@ bool ClassDefImpl::hasNonReferenceSuperClass() const
32313233
}
32323234
}
32333235
return found;
3236+
};
3237+
3238+
/*! Returns \c TRUE iff this class or a class inheriting from this class
3239+
* is \e not defined in an external tag file.
3240+
*/
3241+
bool ClassDefImpl::hasNonReferenceSuperClass() const
3242+
{
3243+
return hasNonReferenceSuperClassRec(this,0);
32343244
}
32353245

32363246
QCString ClassDefImpl::requiresClause() const

0 commit comments

Comments
 (0)