Skip to content

Commit fc70024

Browse files
committed
C#: Remove false-positive reflection calls in dataflow
1 parent 0f5786e commit fc70024

File tree

2 files changed

+20
-2
lines changed

2 files changed

+20
-2
lines changed

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

+5-1
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,11 @@ class NonDelegateDataFlowCall extends DataFlowCall, TNonDelegateCall {
424424
Callable getATarget(boolean static) {
425425
result = dc.getADynamicTarget().getUnboundDeclaration() and static = false
426426
or
427-
result = dc.getAStaticTarget().getUnboundDeclaration() and static = true
427+
result = dc.getAStaticTarget().getUnboundDeclaration() and
428+
static = true and
429+
// In reflection calls, _all_ methods with matching names and arities are considered
430+
// static targets, so we need to exclude them
431+
not dc.isReflection()
428432
}
429433

430434
override ControlFlow::Nodes::ElementNode getControlFlowNode() { result = cfn }

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

+15-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,21 @@ class DispatchCall extends Internal::TDispatchCall {
5252
}
5353

5454
/** Holds if this call uses reflection. */
55-
predicate isReflection() { this instanceof Internal::TDispatchReflectionCall }
55+
predicate isReflection() {
56+
this instanceof Internal::TDispatchReflectionCall
57+
or
58+
this instanceof Internal::TDispatchDynamicElementAccess
59+
or
60+
this instanceof Internal::TDispatchDynamicMemberAccess
61+
or
62+
this instanceof Internal::TDispatchDynamicMethodCall
63+
or
64+
this instanceof Internal::TDispatchDynamicOperatorCall
65+
or
66+
this instanceof Internal::TDispatchDynamicEventAccess
67+
or
68+
this instanceof Internal::TDispatchDynamicObjectCreation
69+
}
5670
}
5771

5872
/** Internal implementation details. */

0 commit comments

Comments
 (0)