diff --git a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll index c2c432fb68e..be183815c71 100644 --- a/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll +++ b/csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll @@ -371,9 +371,21 @@ class NonDelegateDataFlowCall extends DataFlowCall, TNonDelegateCall { /** Gets the underlying call. */ DispatchCall getDispatchCall() { result = dc } + pragma[nomagic] + private predicate hasSourceTarget() { dc.getAStaticTarget().fromSource() } + pragma[nomagic] private FlowSummary::SummarizedCallable getASummarizedCallableTarget() { - result = this.getATarget(_) + // Only use summarized callables with generated summaries in case + // we are not able to dispatch to a source declaration. + exists(boolean static | + result = this.getATarget(static) and + if this.hasSourceTarget() then result.hasManualModel() else any() + | + static = false + or + static = true and not result instanceof RuntimeCallable + ) } pragma[nomagic]