Skip to content

Commit 46f5b13

Browse files
committed
C#: Only dispatch to summarized callables with generated summaries in case there are no source dispatch possibilities.
1 parent eb0925b commit 46f5b13

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

csharp/ql/lib/semmle/code/csharp/dataflow/internal/DataFlowDispatch.qll

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ private import semmle.code.csharp.frameworks.system.Collections
1010
private import semmle.code.csharp.frameworks.system.collections.Generic
1111

1212
/**
13-
* Gets a source declaration of callable `c` that has a body or has
14-
* a flow summary.
13+
* Gets a source declaration of callable `c` that has a body and is
14+
* defined in source.
1515
*/
1616
Callable getCallableForDataFlow(Callable c) {
1717
result = c.getUnboundDeclaration() and
@@ -269,13 +269,19 @@ class NonDelegateDataFlowCall extends DataFlowCall, TNonDelegateCall {
269269
override DataFlowCallable getARuntimeTarget() {
270270
result.asCallable() = getCallableForDataFlow(dc.getADynamicTarget())
271271
or
272-
exists(Callable c, boolean static |
273-
result.asSummarizedCallable() = c and
274-
c = this.getATarget(static)
272+
// Only use summarized callables with generated summaries in case
273+
// we are not able to dispatch to a source declaration.
274+
exists(FlowSummary::SummarizedCallable sc, boolean static |
275+
result.asSummarizedCallable() = sc and
276+
sc = this.getATarget(static) and
277+
not (
278+
sc.applyGeneratedModel() and
279+
dc.getADynamicTarget().getUnboundDeclaration().getFile().fromSource()
280+
)
275281
|
276282
static = false
277283
or
278-
static = true and not c instanceof RuntimeCallable
284+
static = true and not sc instanceof RuntimeCallable
279285
)
280286
}
281287

0 commit comments

Comments
 (0)