Skip to content

Commit 3501778

Browse files
authored
Merge pull request #1739 from hvitved/csharp/ssa/delegate-call-source
C#: Search from delegate creation in `delegateCallSource()`
2 parents 7698240 + e4bd198 commit 3501778

File tree

1 file changed

+9
-11
lines changed
  • csharp/ql/src/semmle/code/csharp/dataflow

1 file changed

+9
-11
lines changed

csharp/ql/src/semmle/code/csharp/dataflow/SSA.qll

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1096,29 +1096,27 @@ module Ssa {
10961096
)
10971097
}
10981098

1099-
private predicate reachableFromDelegateCreation(Expr e) {
1100-
delegateCreation(e, _, _)
1099+
private predicate reachesDelegateCall(Expr e) {
1100+
delegateCall(_, e)
11011101
or
1102-
exists(Expr mid | reachableFromDelegateCreation(mid) | delegateFlowStep(mid, e))
1102+
exists(Expr mid | reachesDelegateCall(mid) | delegateFlowStep(e, mid))
11031103
}
11041104

11051105
pragma[noinline]
1106-
private predicate delegateFlowStepReachable(Expr pred, Expr succ) {
1106+
private predicate delegateFlowStepReaches(Expr pred, Expr succ) {
11071107
delegateFlowStep(pred, succ) and
1108-
reachableFromDelegateCreation(pred)
1108+
reachesDelegateCall(succ)
11091109
}
11101110

1111-
private Expr delegateCallSource(Call c) {
1112-
// Base case
1113-
delegateCall(c, result)
1111+
private Expr delegateCallSource(Callable c) {
1112+
delegateCreation(result, c, _)
11141113
or
1115-
// Recursive case
1116-
delegateFlowStepReachable(result, delegateCallSource(c))
1114+
delegateFlowStepReaches(delegateCallSource(c), result)
11171115
}
11181116

11191117
/** Gets a run-time target for the delegate call `c`. */
11201118
Callable getARuntimeDelegateTarget(Call c) {
1121-
delegateCreation(delegateCallSource(c), result, _)
1119+
delegateCall(c, delegateCallSource(result))
11221120
}
11231121
}
11241122

0 commit comments

Comments
 (0)