Skip to content

Commit 8c4e938

Browse files
committed
C#: Fix context-sensitive dispatch when using base qualifier
1 parent c2bb379 commit 8c4e938

File tree

2 files changed

+18
-10
lines changed

2 files changed

+18
-10
lines changed

csharp/ql/lib/semmle/code/csharp/dispatch/Dispatch.qll

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -723,13 +723,21 @@ private module Internal {
723723
not this = any(AnalyzableFieldOrProperty a).getARead()
724724
}
725725

726+
/**
727+
* For `base` expressions, the extractor provides the type of the base
728+
* class instead of the derived class; for dispatch we need the latter.
729+
*/
730+
private Type getBaseAdjustedType() {
731+
result = this.(BaseAccess).getEnclosingCallable().getDeclaringType()
732+
}
733+
726734
Type getType(boolean isExact) {
735+
result = this.getBaseAdjustedType() and
736+
isExact = false
737+
or
738+
not exists(this.getBaseAdjustedType()) and
727739
result = this.getType() and
728-
if
729-
this instanceof ObjectCreation or
730-
this instanceof BaseAccess
731-
then isExact = true
732-
else isExact = false
740+
if this instanceof ObjectCreation then isExact = true else isExact = false
733741
}
734742
}
735743

csharp/ql/test/library-tests/dataflow/call-sensitivity/CallSensitivityFlow.expected

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ edges
6060
| CallSensitivityFlow.cs:187:17:187:30 | call to method CallMOut : Object | CallSensitivityFlow.cs:187:13:187:13 | access to local variable o : Object | provenance | |
6161
| CallSensitivityFlow.cs:205:40:205:40 | o : Object | CallSensitivityFlow.cs:208:18:208:18 | access to parameter o | provenance | |
6262
| CallSensitivityFlow.cs:239:35:239:35 | o : Object | CallSensitivityFlow.cs:241:17:241:17 | access to parameter o : Object | provenance | |
63-
| CallSensitivityFlow.cs:241:17:241:17 | access to parameter o : Object | CallSensitivityFlow.cs:244:35:244:35 | o : Object | provenance | |
64-
| CallSensitivityFlow.cs:244:35:244:35 | o : Object | CallSensitivityFlow.cs:246:14:246:14 | access to parameter o | provenance | |
63+
| CallSensitivityFlow.cs:241:17:241:17 | access to parameter o : Object | CallSensitivityFlow.cs:256:36:256:36 | o : Object | provenance | |
64+
| CallSensitivityFlow.cs:256:36:256:36 | o : Object | CallSensitivityFlow.cs:258:14:258:14 | access to parameter o | provenance | |
6565
| CallSensitivityFlow.cs:263:17:263:28 | object creation of type Object : Object | CallSensitivityFlow.cs:239:35:239:35 | o : Object | provenance | |
6666
nodes
6767
| CallSensitivityFlow.cs:7:38:7:38 | o : Object | semmle.label | o : Object |
@@ -138,8 +138,8 @@ nodes
138138
| CallSensitivityFlow.cs:208:18:208:18 | access to parameter o | semmle.label | access to parameter o |
139139
| CallSensitivityFlow.cs:239:35:239:35 | o : Object | semmle.label | o : Object |
140140
| CallSensitivityFlow.cs:241:17:241:17 | access to parameter o : Object | semmle.label | access to parameter o : Object |
141-
| CallSensitivityFlow.cs:244:35:244:35 | o : Object | semmle.label | o : Object |
142-
| CallSensitivityFlow.cs:246:14:246:14 | access to parameter o | semmle.label | access to parameter o |
141+
| CallSensitivityFlow.cs:256:36:256:36 | o : Object | semmle.label | o : Object |
142+
| CallSensitivityFlow.cs:258:14:258:14 | access to parameter o | semmle.label | access to parameter o |
143143
| CallSensitivityFlow.cs:263:17:263:28 | object creation of type Object : Object | semmle.label | object creation of type Object : Object |
144144
subpaths
145145
| CallSensitivityFlow.cs:85:26:85:37 | object creation of type Object : Object | CallSensitivityFlow.cs:7:38:7:38 | o : Object | CallSensitivityFlow.cs:11:20:11:20 | access to parameter o : Object | CallSensitivityFlow.cs:85:14:85:44 | call to method FlowThrough |
@@ -165,4 +165,4 @@ subpaths
165165
| CallSensitivityFlow.cs:172:37:172:48 | object creation of type Object : Object | CallSensitivityFlow.cs:172:37:172:48 | object creation of type Object : Object | CallSensitivityFlow.cs:188:14:188:14 | access to local variable o | $@ | CallSensitivityFlow.cs:188:14:188:14 | access to local variable o | access to local variable o |
166166
| CallSensitivityFlow.cs:182:21:182:32 | object creation of type Object : Object | CallSensitivityFlow.cs:182:21:182:32 | object creation of type Object : Object | CallSensitivityFlow.cs:208:18:208:18 | access to parameter o | $@ | CallSensitivityFlow.cs:208:18:208:18 | access to parameter o | access to parameter o |
167167
| CallSensitivityFlow.cs:185:21:185:32 | object creation of type Object : Object | CallSensitivityFlow.cs:185:21:185:32 | object creation of type Object : Object | CallSensitivityFlow.cs:164:14:164:14 | access to parameter o | $@ | CallSensitivityFlow.cs:164:14:164:14 | access to parameter o | access to parameter o |
168-
| CallSensitivityFlow.cs:263:17:263:28 | object creation of type Object : Object | CallSensitivityFlow.cs:263:17:263:28 | object creation of type Object : Object | CallSensitivityFlow.cs:246:14:246:14 | access to parameter o | $@ | CallSensitivityFlow.cs:246:14:246:14 | access to parameter o | access to parameter o |
168+
| CallSensitivityFlow.cs:263:17:263:28 | object creation of type Object : Object | CallSensitivityFlow.cs:263:17:263:28 | object creation of type Object : Object | CallSensitivityFlow.cs:258:14:258:14 | access to parameter o | $@ | CallSensitivityFlow.cs:258:14:258:14 | access to parameter o | access to parameter o |

0 commit comments

Comments
 (0)