Merge pull request #18269 from hvitved/csharp/dataflow-reflection-call

C#: Remove false-positive reflection calls in dataflow
This commit is contained in:
Tom Hvitved
2024-12-12 14:43:13 +01:00
committed by GitHub
2 changed files with 20 additions and 2 deletions

View File

@@ -424,7 +424,11 @@ class NonDelegateDataFlowCall extends DataFlowCall, TNonDelegateCall {
Callable getATarget(boolean static) {
result = dc.getADynamicTarget().getUnboundDeclaration() and static = false
or
result = dc.getAStaticTarget().getUnboundDeclaration() and static = true
result = dc.getAStaticTarget().getUnboundDeclaration() and
static = true and
// In reflection calls, _all_ methods with matching names and arities are considered
// static targets, so we need to exclude them
not dc.isReflection()
}
override ControlFlow::Nodes::ElementNode getControlFlowNode() { result = cfn }

View File

@@ -52,7 +52,21 @@ class DispatchCall extends Internal::TDispatchCall {
}
/** Holds if this call uses reflection. */
predicate isReflection() { this instanceof Internal::TDispatchReflectionCall }
predicate isReflection() {
this instanceof Internal::TDispatchReflectionCall
or
this instanceof Internal::TDispatchDynamicElementAccess
or
this instanceof Internal::TDispatchDynamicMemberAccess
or
this instanceof Internal::TDispatchDynamicMethodCall
or
this instanceof Internal::TDispatchDynamicOperatorCall
or
this instanceof Internal::TDispatchDynamicEventAccess
or
this instanceof Internal::TDispatchDynamicObjectCreation
}
}
/** Internal implementation details. */