This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Add sanity check in Sema::getDestructorName to prevent nullptr dereference
ClosedPublic

Authored by shafik on Dec 22 2022, 6:08 PM.

Details

Summary

Currently in Sema::getDestructorName we call SS.getScopeRep()->getPrefix() but SS.getScopeRep() can return nullptr because LookupInNestedNameSpec(...) called a little before can invalidate SS.

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

Diff Detail

Event Timeline

shafik created this revision.Dec 22 2022, 6:08 PM
Herald added a project: Restricted Project. · View Herald TranscriptDec 22 2022, 6:08 PM
shafik requested review of this revision.Dec 22 2022, 6:08 PM
tahonermann added inline comments.
clang/lib/Sema/SemaExprCXX.cpp
394

CXXScopeSpec::isSet() is apparently (intended to be) deprecated.

clang/include/clang/Sema/DeclSpec.h:
 209   /// Deprecated.  Some call sites intend isNotEmpty() while others intend
 210   /// isValid().
 211   bool isSet() const { return getScopeRep() != nullptr; }

It sounds like this should instead call .isValid() or .isNotEmpty(), but I'm not sure which.

aaron.ballman added inline comments.Jan 5 2023, 1:39 PM
clang/lib/Sema/SemaExprCXX.cpp
394

We want to use isValid() -- isNotEmpty() will return true when the scope spec is present but invalid, so the call to SS.getScopeRep()->getPrefix() would crash in that case.

Also, don't forget to add a release note for the fix. :-)

shafik updated this revision to Diff 491554.Jan 23 2023, 4:43 PM
shafik marked 2 inline comments as done.
  • Switched to isValid() over isSet()
  • Added release note
This revision is now accepted and ready to land.Jan 24 2023, 5:54 AM
This revision was landed with ongoing or failed builds.Jan 25 2023, 10:49 AM
This revision was automatically updated to reflect the committed changes.
Herald added a project: Restricted Project. · View Herald TranscriptJan 25 2023, 10:49 AM