Skip to content

Commit 5330211

Browse files
committed
C#: Implement missingArgumentCallExclude and multipleArgumentCallExclude
1 parent b470c36 commit 5330211

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

csharp/ql/consistency-queries/DataFlowConsistency.ql

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,44 @@ private module Input implements InputSig<CsharpDataFlow> {
7272
}
7373

7474
predicate reverseReadExclude(Node n) { n.asExpr() = any(AwaitExpr ae).getExpr() }
75+
76+
predicate missingArgumentCallExclude(ArgumentNode arg) {
77+
// TODO: Remove once object initializers are modeled properly
78+
arg.(Private::PostUpdateNodes::ObjectInitializerNode).getInitializer() instanceof
79+
ObjectInitializer
80+
or
81+
// TODO: Remove once underlying issue is fixed
82+
exists(QualifiableExpr qe |
83+
qe.isConditional() and
84+
qe.getQualifier() = arg.asExpr()
85+
)
86+
}
87+
88+
predicate multipleArgumentCallExclude(ArgumentNode arg, DataFlowCall call) {
89+
isArgumentNode(arg, call, _) and
90+
(
91+
// TODO: Remove once object initializers are modeled properly
92+
arg =
93+
any(Private::PostUpdateNodes::ObjectInitializerNode init |
94+
init.argumentOf(call, _) and
95+
init.getInitializer().getNumberOfChildren() > 1
96+
)
97+
or
98+
exists(ControlFlow::Nodes::ElementNode cfn, ControlFlow::Nodes::Split split |
99+
exists(arg.asExprAtNode(cfn))
100+
|
101+
split = cfn.getASplit() and
102+
not split = call.getControlFlowNode().getASplit()
103+
or
104+
split = call.getControlFlowNode().getASplit() and
105+
not split = cfn.getASplit()
106+
)
107+
or
108+
call instanceof TransitiveCapturedDataFlowCall
109+
or
110+
call.(NonDelegateDataFlowCall).getDispatchCall().isReflection()
111+
)
112+
}
75113
}
76114

77115
import MakeConsistency<CsharpDataFlow, CsharpTaintTracking, Input>

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2032,7 +2032,7 @@ abstract class PostUpdateNode extends Node {
20322032
abstract Node getPreUpdateNode();
20332033
}
20342034

2035-
private module PostUpdateNodes {
2035+
module PostUpdateNodes {
20362036
class ObjectCreationNode extends PostUpdateNode, ExprNode, TExprNode {
20372037
private ObjectCreation oc;
20382038

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,9 @@ class DispatchCall extends Internal::TDispatchCall {
5050
RuntimeCallable getADynamicTargetInCallContext(DispatchCall ctx) {
5151
result = Internal::getADynamicTargetInCallContext(this, ctx)
5252
}
53+
54+
/** Holds if this call uses reflection. */
55+
predicate isReflection() { this instanceof Internal::TDispatchReflectionCall }
5356
}
5457

5558
/** Internal implementation details. */

0 commit comments

Comments
 (0)