This is an archive of the discontinued LLVM Phabricator instance.

Fix stack crash in classIsDerivedFrom triggered by clang-tidy
Needs ReviewPublic

Authored by datacompboy on May 20 2022, 10:04 AM.

Details

Summary

Protect classIsDerivedFrom from run-out-of-stack crash and infinity loop.

Rewrite recursion to loop-over-stack and add checks for complexity to avoid crash on deep definition or infinify recursion.

This fixes https://github.com/llvm/llvm-project/issues/55614

Diff Detail

Event Timeline

datacompboy created this revision.May 20 2022, 10:04 AM
Herald added a project: Restricted Project. · View Herald TranscriptMay 20 2022, 10:04 AM
datacompboy requested review of this revision.May 20 2022, 10:04 AM
Herald added projects: Restricted Project, Restricted Project. · View Herald TranscriptMay 20 2022, 10:04 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript
njames93 added a subscriber: njames93.

Do you know of any other instances where this issue could surface?

Please can you add a line to the Improved Checks section in clang-tools-extra/docs/ReleaseNotes.rst about this fix. Make sure it is in alphabetical order.

clang-tools-extra/test/clang-tidy/infrastructure/recursive-templates.cpp
2 ↗(On Diff #431003)

Can you narrow down the check list to just include a check is causing the crash.
Also given we are only ensuring there is no crash, we don't need to invoke FileCheck. clang-tidy will return non-zero if it crashes, causing the whole test to fail.

8 ↗(On Diff #431003)

This is different to the reproducer in the bug report as it doesn't have an instantiation of the struct in this test, unlike the bug report.

11–13 ↗(On Diff #431003)

Definitely unrelated to this check and could safely be removed.

Do you know of any other instances where this issue could surface?

I didn't found any other cases where isDerivedFrom used directly, only in couple of internal checks, none of which are part of clang distribution.

Please can you add a line to the Improved Checks section in clang-tools-extra/docs/ReleaseNotes.rst about this fix. Make sure it is in alphabetical order.

I removed test case from the clang-tidy and made a unit-test instead, so it's not affecting this section.
Do you think it worth to include in any other release notes sections?

LegalizeAdulthood resigned from this revision.Mar 29 2023, 8:57 AM