Skip to content

Commit f06a69e

Browse files
committed
Data flow: Prevent context-sensitive dispatch in source call contexts
1 parent bac28b9 commit f06a69e

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
unexpectedModel
2-
| Unexpected contentbased-summary found: Models;HigherOrderParameters;false;Apply;(System.Func<System.Object,System.Object>,System.Object);;Argument[1];ReturnValue;value;dfc-generated |
32
expectedModel

shared/dataflow/codeql/dataflow/internal/DataFlowImplCommon.qll

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -494,6 +494,10 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
494494
tgts = strictcount(Callable tgt | relevantCallEdgeIn(call, tgt)) and
495495
ctxtgts < tgts
496496
)
497+
or
498+
// If only a single lambda can reach `call`, we still want to check for the call
499+
// context, since lambdas outside the codebase may reach as well
500+
exists(viableCallableLambda(call, TCallSome(ctx)))
497501
}
498502

499503
/**
@@ -739,7 +743,13 @@ module MakeImplCommon<LocationSig Location, InputSig<Location> Lang> {
739743
/** Holds if `call` does not have a reduced set of dispatch targets in call context `ctx`. */
740744
bindingset[call, ctx]
741745
predicate viableImplNotCallContextReduced(Call call, CallContext ctx) {
742-
not Input2::callContextAffectsDispatch(call, ctx)
746+
not Input2::callContextAffectsDispatch(call, ctx) and
747+
// When sources have call contexts (using `FlowFeature`s), we check that `call` can
748+
// dispatch in all possible call contexts
749+
not (
750+
ctx = TSomeCall() and
751+
any(CallSet calls).asSome().contains(call)
752+
)
743753
}
744754

745755
/**

0 commit comments

Comments
 (0)