Skip to content
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] Reorder checks to protect against a null pointer dereference. #66764

Merged
merged 1 commit into from
Sep 20, 2023

Conversation

martinboehme
Copy link
Contributor

I've received a report of a null pointer dereference happening on the
LocDst->getType() dereference. I wasn't unfortunately able to find a repro,
but I'd argue the new version is better for the reduced indentation alone.

…reference.

I've received a report of a null pointer dereference happening on the
`LocDst->getType()` dereference. I wasn't unfortunately able to find a repro,
but I'd argue the new version is better for the reduced indentation alone.
@llvmbot 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
@llvmbot
Copy link
Member

llvmbot commented Sep 19, 2023

@llvm/pr-subscribers-clang-analysis

@llvm/pr-subscribers-clang

Changes

I've received a report of a null pointer dereference happening on the
LocDst->getType() dereference. I wasn't unfortunately able to find a repro,
but I'd argue the new version is better for the reduced indentation alone.


Full diff: https://github.com/llvm/llvm-project/pull/66764.diff

1 Files Affected:

  • (modified) clang/lib/Analysis/FlowSensitive/Transfer.cpp (+7-6)
diff --git a/clang/lib/Analysis/FlowSensitive/Transfer.cpp b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
index b510114a7a355eb..2414a1cc026af5f 100644
--- a/clang/lib/Analysis/FlowSensitive/Transfer.cpp
+++ b/clang/lib/Analysis/FlowSensitive/Transfer.cpp
@@ -531,17 +531,18 @@ class TransferVisitor : public ConstStmtVisitor<TransferVisitor> {
       auto *LocDst =
           cast_or_null<RecordStorageLocation>(Env.getStorageLocation(*Arg0));
 
+      if (LocSrc == nullptr || LocDst == nullptr)
+        return;
+
       // The assignment operators are different from the type of the destination
-      // in this model (i.e. in one of their base classes). This must be very rare
-      // and we just bail.
+      // in this model (i.e. in one of their base classes). This must be very
+      // rare and we just bail.
       if (Method->getThisObjectType().getCanonicalType().getUnqualifiedType() !=
           LocDst->getType().getCanonicalType().getUnqualifiedType())
         return;
 
-      if (LocSrc != nullptr && LocDst != nullptr) {
-        copyRecord(*LocSrc, *LocDst, Env);
-        Env.setStorageLocation(*S, *LocDst);
-      }
+      copyRecord(*LocSrc, *LocDst, Env);
+      Env.setStorageLocation(*S, *LocDst);
     }
   }
 

Copy link
Member

@MaskRay MaskRay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. It'll be nice to have a test, but I think it is fine to land this now... and will address an internal crash.

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
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants