-
Notifications
You must be signed in to change notification settings - Fork 10.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][dataflow] Fix two null pointer dereferences in getMemberForAccessor()
.
#66742
Merged
martinboehme
merged 1 commit into
llvm:main
from
martinboehme:piper_export_cl_566528374
Sep 19, 2023
Merged
[clang][dataflow] Fix two null pointer dereferences in getMemberForAccessor()
.
#66742
martinboehme
merged 1 commit into
llvm:main
from
martinboehme:piper_export_cl_566528374
Sep 19, 2023
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
llvmbot
added
clang
Clang issues not falling into any other category
clang:dataflow
Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html
clang:analysis
labels
Sep 19, 2023
@llvm/pr-subscribers-clang @llvm/pr-subscribers-clang-analysis ChangesThe additions to the test trigger crashes without the fixes. Full diff: https://github.com/llvm/llvm-project/pull/66742.diff 2 Files Affected:
diff --git a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
index 26e097349057238..98128693e145da4 100644
--- a/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
+++ b/clang/lib/Analysis/FlowSensitive/DataflowEnvironment.cpp
@@ -289,11 +289,14 @@ static void insertIfFunction(const Decl &D,
}
static MemberExpr *getMemberForAccessor(const CXXMemberCallExpr &C) {
+ if (!C.getMethodDecl())
+ return nullptr;
auto *Body = dyn_cast_or_null<CompoundStmt>(C.getMethodDecl()->getBody());
if (!Body || Body->size() != 1)
return nullptr;
if (auto *RS = dyn_cast<ReturnStmt>(*Body->body_begin()))
- return dyn_cast<MemberExpr>(RS->getRetValue()->IgnoreParenImpCasts());
+ if (RS->getRetValue() != nullptr)
+ return dyn_cast<MemberExpr>(RS->getRetValue()->IgnoreParenImpCasts());
return nullptr;
}
diff --git a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
index 14188f5acd5b36e..e8cbca756460369 100644
--- a/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
+++ b/clang/unittests/Analysis/FlowSensitive/TransferTest.cpp
@@ -1463,6 +1463,7 @@ TEST(TransferTest, StructModeledFieldsWithAccessor) {
int getIntNotAccessed() const { return IntNotAccessed; }
int getIntNoDefinition() const;
int &getIntRef() { return IntRef; }
+ void returnVoid() const { return; }
};
void target() {
@@ -1473,6 +1474,14 @@ TEST(TransferTest, StructModeledFieldsWithAccessor) {
int i2 = s.getWithInc(1);
int i3 = s.getIntNoDefinition();
int &iref = s.getIntRef();
+
+ // Regression test: Don't crash on an indirect call (which doesn't have
+ // an associated `CXXMethodDecl`).
+ auto ptr_to_member_fn = &S::getPtr;
+ p1 = (s.*ptr_to_member_fn)();
+
+ // Regression test: Don't crash on a return statement without a value.
+ s.returnVoid();
// [[p]]
}
)";
|
sam-mccall
approved these changes
Sep 19, 2023
MaskRay
approved these changes
Sep 19, 2023
hokein
approved these changes
Sep 19, 2023
…ccessor()`. The additions to the test trigger crashes without the fixes.
martinboehme
force-pushed
the
piper_export_cl_566528374
branch
from
September 19, 2023 06:50
110ac1d
to
5cdc525
Compare
ZijunZhaoCCK
pushed a commit
to ZijunZhaoCCK/llvm-project
that referenced
this pull request
Sep 19, 2023
…ccessor()`. (llvm#66742) The additions to the test trigger crashes without the fixes.
This was referenced Sep 19, 2023
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
clang:analysis
clang:dataflow
Clang Dataflow Analysis framework - https://clang.llvm.org/docs/DataFlowAnalysisIntro.html
clang
Clang issues not falling into any other category
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The additions to the test trigger crashes without the fixes.