Skip to content

Commit b2b8aa6

Browse files
committed
C#: Fix broken viableImplInCallContext implementation
1 parent 4c5c0ef commit b2b8aa6

File tree

2 files changed

+17
-33
lines changed

2 files changed

+17
-33
lines changed

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

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -176,9 +176,15 @@ private module DispatchImpl {
176176
*/
177177
DataFlowCallable viableImplInCallContext(NonDelegateDataFlowCall call, DataFlowCall ctx) {
178178
result.getUnderlyingCallable() =
179-
call.getDispatchCall()
180-
.getADynamicTargetInCallContext(ctx.(NonDelegateDataFlowCall).getDispatchCall())
181-
.getUnboundDeclaration()
179+
getCallableForDataFlow(call.getDispatchCall()
180+
.getADynamicTargetInCallContext(ctx.(NonDelegateDataFlowCall).getDispatchCall())
181+
.getUnboundDeclaration())
182+
or
183+
exists(DataFlowCallable encl |
184+
encl = viableCallable(ctx) and
185+
mayBenefitFromCallContext(call, encl) and
186+
result = call.getASummaryTarget()
187+
)
182188
}
183189
}
184190

@@ -342,9 +348,8 @@ class NonDelegateDataFlowCall extends DataFlowCall, TNonDelegateCall {
342348
/** Gets the underlying call. */
343349
DispatchCall getDispatchCall() { result = dc }
344350

345-
override DataFlowCallable getARuntimeTarget() {
346-
result.asCallable() = getCallableForDataFlow(dc.getADynamicTarget())
347-
or
351+
/** Gets a summarized call target, if any. */
352+
DataFlowCallable getASummaryTarget() {
348353
exists(Callable c, boolean static |
349354
result.asSummarizedCallable() = c and
350355
c = this.getATarget(static)
@@ -355,6 +360,12 @@ class NonDelegateDataFlowCall extends DataFlowCall, TNonDelegateCall {
355360
)
356361
}
357362

363+
override DataFlowCallable getARuntimeTarget() {
364+
result.asCallable() = getCallableForDataFlow(dc.getADynamicTarget())
365+
or
366+
result = this.getASummaryTarget()
367+
}
368+
358369
/** Gets a static or dynamic target of this call. */
359370
Callable getATarget(boolean static) {
360371
result = dc.getADynamicTarget().getUnboundDeclaration() and static = false

csharp/ql/test/library-tests/dataflow/collections/CollectionFlow.expected

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -187,12 +187,6 @@ edges
187187
| CollectionFlow.cs:373:52:373:53 | access to parameter ts [element] : A | CollectionFlow.cs:373:52:373:56 | access to array element |
188188
| CollectionFlow.cs:373:52:373:53 | access to parameter ts [element] : A | CollectionFlow.cs:373:52:373:56 | access to array element |
189189
| CollectionFlow.cs:375:49:375:52 | list [element] : A | CollectionFlow.cs:375:63:375:66 | access to parameter list [element] : A |
190-
| CollectionFlow.cs:375:49:375:52 | list [element] : A | CollectionFlow.cs:375:63:375:66 | access to parameter list [element] : A |
191-
| CollectionFlow.cs:375:49:375:52 | list [element] : A | CollectionFlow.cs:375:63:375:66 | access to parameter list [element] : A |
192-
| CollectionFlow.cs:375:49:375:52 | list [element] : A | CollectionFlow.cs:375:63:375:66 | access to parameter list [element] : A |
193-
| CollectionFlow.cs:375:63:375:66 | access to parameter list [element] : A | CollectionFlow.cs:375:63:375:69 | access to indexer |
194-
| CollectionFlow.cs:375:63:375:66 | access to parameter list [element] : A | CollectionFlow.cs:375:63:375:69 | access to indexer |
195-
| CollectionFlow.cs:375:63:375:66 | access to parameter list [element] : A | CollectionFlow.cs:375:63:375:69 | access to indexer |
196190
| CollectionFlow.cs:375:63:375:66 | access to parameter list [element] : A | CollectionFlow.cs:375:63:375:69 | access to indexer |
197191
| CollectionFlow.cs:377:61:377:64 | dict [element, property Value] : A | CollectionFlow.cs:377:75:377:78 | access to parameter dict [element, property Value] : A |
198192
| CollectionFlow.cs:377:75:377:78 | access to parameter dict [element, property Value] : A | CollectionFlow.cs:377:75:377:81 | access to indexer |
@@ -204,12 +198,6 @@ edges
204198
| CollectionFlow.cs:381:41:381:42 | access to parameter ts [element] : A | CollectionFlow.cs:381:41:381:45 | access to array element : A |
205199
| CollectionFlow.cs:381:41:381:42 | access to parameter ts [element] : A | CollectionFlow.cs:381:41:381:45 | access to array element : A |
206200
| CollectionFlow.cs:383:43:383:46 | list [element] : A | CollectionFlow.cs:383:52:383:55 | access to parameter list [element] : A |
207-
| CollectionFlow.cs:383:43:383:46 | list [element] : A | CollectionFlow.cs:383:52:383:55 | access to parameter list [element] : A |
208-
| CollectionFlow.cs:383:43:383:46 | list [element] : A | CollectionFlow.cs:383:52:383:55 | access to parameter list [element] : A |
209-
| CollectionFlow.cs:383:43:383:46 | list [element] : A | CollectionFlow.cs:383:52:383:55 | access to parameter list [element] : A |
210-
| CollectionFlow.cs:383:52:383:55 | access to parameter list [element] : A | CollectionFlow.cs:383:52:383:58 | access to indexer : A |
211-
| CollectionFlow.cs:383:52:383:55 | access to parameter list [element] : A | CollectionFlow.cs:383:52:383:58 | access to indexer : A |
212-
| CollectionFlow.cs:383:52:383:55 | access to parameter list [element] : A | CollectionFlow.cs:383:52:383:58 | access to indexer : A |
213201
| CollectionFlow.cs:383:52:383:55 | access to parameter list [element] : A | CollectionFlow.cs:383:52:383:58 | access to indexer : A |
214202
| CollectionFlow.cs:385:58:385:61 | dict [element, property Value] : A | CollectionFlow.cs:385:67:385:70 | access to parameter dict [element, property Value] : A |
215203
| CollectionFlow.cs:385:67:385:70 | access to parameter dict [element, property Value] : A | CollectionFlow.cs:385:67:385:73 | access to indexer : A |
@@ -402,12 +390,6 @@ nodes
402390
| CollectionFlow.cs:373:52:373:53 | access to parameter ts [element] : A | semmle.label | access to parameter ts [element] : A |
403391
| CollectionFlow.cs:373:52:373:56 | access to array element | semmle.label | access to array element |
404392
| CollectionFlow.cs:375:49:375:52 | list [element] : A | semmle.label | list [element] : A |
405-
| CollectionFlow.cs:375:49:375:52 | list [element] : A | semmle.label | list [element] : A |
406-
| CollectionFlow.cs:375:49:375:52 | list [element] : A | semmle.label | list [element] : A |
407-
| CollectionFlow.cs:375:49:375:52 | list [element] : A | semmle.label | list [element] : A |
408-
| CollectionFlow.cs:375:63:375:66 | access to parameter list [element] : A | semmle.label | access to parameter list [element] : A |
409-
| CollectionFlow.cs:375:63:375:66 | access to parameter list [element] : A | semmle.label | access to parameter list [element] : A |
410-
| CollectionFlow.cs:375:63:375:66 | access to parameter list [element] : A | semmle.label | access to parameter list [element] : A |
411393
| CollectionFlow.cs:375:63:375:66 | access to parameter list [element] : A | semmle.label | access to parameter list [element] : A |
412394
| CollectionFlow.cs:375:63:375:69 | access to indexer | semmle.label | access to indexer |
413395
| CollectionFlow.cs:377:61:377:64 | dict [element, property Value] : A | semmle.label | dict [element, property Value] : A |
@@ -424,16 +406,7 @@ nodes
424406
| CollectionFlow.cs:381:41:381:45 | access to array element : A | semmle.label | access to array element : A |
425407
| CollectionFlow.cs:381:41:381:45 | access to array element : A | semmle.label | access to array element : A |
426408
| CollectionFlow.cs:383:43:383:46 | list [element] : A | semmle.label | list [element] : A |
427-
| CollectionFlow.cs:383:43:383:46 | list [element] : A | semmle.label | list [element] : A |
428-
| CollectionFlow.cs:383:43:383:46 | list [element] : A | semmle.label | list [element] : A |
429-
| CollectionFlow.cs:383:43:383:46 | list [element] : A | semmle.label | list [element] : A |
430409
| CollectionFlow.cs:383:52:383:55 | access to parameter list [element] : A | semmle.label | access to parameter list [element] : A |
431-
| CollectionFlow.cs:383:52:383:55 | access to parameter list [element] : A | semmle.label | access to parameter list [element] : A |
432-
| CollectionFlow.cs:383:52:383:55 | access to parameter list [element] : A | semmle.label | access to parameter list [element] : A |
433-
| CollectionFlow.cs:383:52:383:55 | access to parameter list [element] : A | semmle.label | access to parameter list [element] : A |
434-
| CollectionFlow.cs:383:52:383:58 | access to indexer : A | semmle.label | access to indexer : A |
435-
| CollectionFlow.cs:383:52:383:58 | access to indexer : A | semmle.label | access to indexer : A |
436-
| CollectionFlow.cs:383:52:383:58 | access to indexer : A | semmle.label | access to indexer : A |
437410
| CollectionFlow.cs:383:52:383:58 | access to indexer : A | semmle.label | access to indexer : A |
438411
| CollectionFlow.cs:385:58:385:61 | dict [element, property Value] : A | semmle.label | dict [element, property Value] : A |
439412
| CollectionFlow.cs:385:67:385:70 | access to parameter dict [element, property Value] : A | semmle.label | access to parameter dict [element, property Value] : A |

0 commit comments

Comments
 (0)