C#: Implement missingArgumentCallExclude and multipleArgumentCallExclude

This commit is contained in:
Tom Hvitved
2023-08-31 13:36:20 +02:00
parent b470c36c82
commit 53302117a1
3 changed files with 42 additions and 1 deletions

View File

@@ -72,6 +72,44 @@ private module Input implements InputSig<CsharpDataFlow> {
}
predicate reverseReadExclude(Node n) { n.asExpr() = any(AwaitExpr ae).getExpr() }
predicate missingArgumentCallExclude(ArgumentNode arg) {
// TODO: Remove once object initializers are modeled properly
arg.(Private::PostUpdateNodes::ObjectInitializerNode).getInitializer() instanceof
ObjectInitializer
or
// TODO: Remove once underlying issue is fixed
exists(QualifiableExpr qe |
qe.isConditional() and
qe.getQualifier() = arg.asExpr()
)
}
predicate multipleArgumentCallExclude(ArgumentNode arg, DataFlowCall call) {
isArgumentNode(arg, call, _) and
(
// TODO: Remove once object initializers are modeled properly
arg =
any(Private::PostUpdateNodes::ObjectInitializerNode init |
init.argumentOf(call, _) and
init.getInitializer().getNumberOfChildren() > 1
)
or
exists(ControlFlow::Nodes::ElementNode cfn, ControlFlow::Nodes::Split split |
exists(arg.asExprAtNode(cfn))
|
split = cfn.getASplit() and
not split = call.getControlFlowNode().getASplit()
or
split = call.getControlFlowNode().getASplit() and
not split = cfn.getASplit()
)
or
call instanceof TransitiveCapturedDataFlowCall
or
call.(NonDelegateDataFlowCall).getDispatchCall().isReflection()
)
}
}
import MakeConsistency<CsharpDataFlow, CsharpTaintTracking, Input>

View File

@@ -2032,7 +2032,7 @@ abstract class PostUpdateNode extends Node {
abstract Node getPreUpdateNode();
}
private module PostUpdateNodes {
module PostUpdateNodes {
class ObjectCreationNode extends PostUpdateNode, ExprNode, TExprNode {
private ObjectCreation oc;

View File

@@ -50,6 +50,9 @@ class DispatchCall extends Internal::TDispatchCall {
RuntimeCallable getADynamicTargetInCallContext(DispatchCall ctx) {
result = Internal::getADynamicTargetInCallContext(this, ctx)
}
/** Holds if this call uses reflection. */
predicate isReflection() { this instanceof Internal::TDispatchReflectionCall }
}
/** Internal implementation details. */