Skip to content

Commit 628aa86

Browse files
committed
C#: Fix enclosing DataFlowCallable of ObjectInitMethods with multiple bodies.
1 parent a13581b commit 628aa86

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

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

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,20 @@ newtype TReturnKind =
2727

2828
private predicate hasMultipleSourceLocations(Callable c) { strictcount(getASourceLocation(c)) > 1 }
2929

30+
private predicate objectInitEntry(ObjectInitMethod m, ControlFlowElement first) {
31+
exists(ControlFlow::Nodes::EntryNode en |
32+
en.getCallable() = m and first.getControlFlowNode() = en.getASuccessor()
33+
)
34+
}
35+
3036
private module NearestBodyLocationInput implements NearestLocationInputSig {
3137
class C = ControlFlowElement;
3238

3339
predicate relevantLocations(ControlFlowElement body, Location l1, Location l2) {
3440
exists(Callable c |
3541
hasMultipleSourceLocations(c) and
3642
l1 = getASourceLocation(c) and
37-
body = c.getBody() and
43+
(body = c.getBody() or objectInitEntry(c, body)) and
3844
l2 = body.getLocation()
3945
)
4046
}
@@ -207,7 +213,9 @@ class DataFlowCallable extends TDataFlowCallable {
207213
private ControlFlow::Nodes::ElementNode getAMultiBodyEntryNode(ControlFlow::BasicBlock bb, int i) {
208214
this.isMultiBodied() and
209215
exists(ControlFlowElement body, Location l |
210-
body = this.asCallable(l).getBody() and
216+
body = this.asCallable(l).getBody() or
217+
objectInitEntry(this.asCallable(l), body)
218+
|
211219
NearestLocation<NearestBodyLocationInput>::nearestLocation(body, l, _) and
212220
result = body.getAControlFlowEntryNode()
213221
) and

0 commit comments

Comments
 (0)