-
Notifications
You must be signed in to change notification settings - Fork 11.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Clang] Prevent null pointer dereference in Sema::CodeCompleteQualifiedId() #90490
[Clang] Prevent null pointer dereference in Sema::CodeCompleteQualifiedId() #90490
Conversation
…edId() The null pointer dereference issue seems happening with in the expression NNS->getAsType(). Although dyn_cast_or_null<TemplateTypeParmType>() correctly handles null pointers, it doesn’t prevent the subsequent dereferencing operation. The fix ensures that NNS pointer is not null before calling the getAsType() method, thus preventing potential runtime errors caused by attempting to access a null pointer.
@llvm/pr-subscribers-clang Author: None (smanna12) Changes…edId() The null pointer dereference issue seems happening with in the expression NNS->getAsType(). Although dyn_cast_or_null<TemplateTypeParmType>() correctly handles null pointers, it doesn’t prevent the subsequent dereferencing operation. The fix ensures that NNS pointer is not null before calling the getAsType() method, thus preventing potential runtime errors caused by attempting to access a null pointer. Full diff: https://github.com/llvm/llvm-project/pull/90490.diff 1 Files Affected:
diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp
index c335017f243eb2..3f0ab10646fe5d 100644
--- a/clang/lib/Sema/SemaCodeComplete.cpp
+++ b/clang/lib/Sema/SemaCodeComplete.cpp
@@ -6714,14 +6714,16 @@ void Sema::CodeCompleteQualifiedId(Scope *S, CXXScopeSpec &SS,
// If the scope is a concept-constrained type parameter, infer nested
// members based on the constraints.
- if (const auto *TTPT =
- dyn_cast_or_null<TemplateTypeParmType>(NNS->getAsType())) {
- for (const auto &R : ConceptInfo(*TTPT, S).members()) {
- if (R.Operator != ConceptInfo::Member::Colons)
- continue;
- Results.AddResult(CodeCompletionResult(
- R.render(*this, CodeCompleter->getAllocator(),
- CodeCompleter->getCodeCompletionTUInfo())));
+ if (NNS) {
+ if (const auto *TTPT =
+ dyn_cast_or_null<TemplateTypeParmType>(NNS->getAsType())) {
+ for (const auto &R : ConceptInfo(*TTPT, S).members()) {
+ if (R.Operator != ConceptInfo::Member::Colons)
+ continue;
+ Results.AddResult(CodeCompletionResult(
+ R.render(*this, CodeCompleter->getAllocator(),
+ CodeCompleter->getCodeCompletionTUInfo())));
+ }
}
}
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good, I will let Tom make the final accept.
Adding Sam McCall as an additional reviewer since he originally authored this code in commit a76e68c. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The change looks good to me. I recommend giving @sam-mccall a day or so to comment if he wants to.
Thanks @tahonermann for reviews! |
@sam-mccall, could you please review/comment on the fix? Thank you |
I will followup any comments from @sam-mccall in a separate PR. Merging this PR. Thanks everyone for reviews! |
The null pointer dereference issue seems happening with in the expression NNS->getAsType().
Although dyn_cast_or_null() correctly handles null pointers, it doesn’t prevent the subsequent dereferencing operation.
The fix ensures that NNS pointer is not null before calling the getAsType() method, thus preventing potential runtime errors caused by attempting to access a null pointer.