[analyzer] GenericTaint: Don't expect CallEvent to always have a Decl.
authorArtem Dergachev <artem.dergachev@gmail.com>
Mon, 20 Apr 2020 12:30:30 +0000 (15:30 +0300)
committerArtem Dergachev <artem.dergachev@gmail.com>
Mon, 20 Apr 2020 12:31:43 +0000 (15:31 +0300)
This isn't the case when the callee is completely unknown,
eg. when it is a symbolic function pointer.

clang/lib/StaticAnalyzer/Checkers/GenericTaintChecker.cpp
clang/test/Analysis/taint-generic.c

index 1f3e749..c06d2fc 100644 (file)
@@ -110,7 +110,9 @@ private:
 
     static Optional<FunctionData> create(const CallEvent &Call,
                                          const CheckerContext &C) {
-      assert(Call.getDecl());
+      if (!Call.getDecl())
+        return None;
+
       const FunctionDecl *FDecl = Call.getDecl()->getAsFunction();
       if (!FDecl || (FDecl->getKind() != Decl::Function &&
                      FDecl->getKind() != Decl::CXXMethod))
index a299501..1cc1913 100644 (file)
@@ -390,3 +390,7 @@ void testConfigurationSinks() {
   mySink(1, 2, x);
   // expected-warning@-1 {{Untrusted data is passed to a user-defined sink}}
 }
+
+void testUnknownFunction(void (*foo)(void)) {
+  foo(); // no-crash
+}