Skip to content

Commit 7400b47

Browse files
authored
Merge pull request github#14108 from hvitved/dataflow/more-consistency-checks
Data flow: Add `ArgumentNode` consistency checks
2 parents bb85f87 + d3558f8 commit 7400b47

File tree

39 files changed

+153
-51
lines changed

39 files changed

+153
-51
lines changed

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-consistency.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ uniqueType
44
uniqueNodeLocation
55
missingLocation
66
uniqueNodeToString
7-
missingToString
87
parameterCallable
98
localFlowIsLocal
109
readStepIsLocal
@@ -139,3 +138,5 @@ uniqueParameterNodeAtPosition
139138
uniqueParameterNodePosition
140139
uniqueContentApprox
141140
identityLocalStep
141+
missingArgumentCall
142+
multipleArgumentCall

cpp/ql/test/library-tests/dataflow/dataflow-tests/dataflow-ir-consistency.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ uniqueType
44
uniqueNodeLocation
55
missingLocation
66
uniqueNodeToString
7-
missingToString
87
parameterCallable
98
localFlowIsLocal
109
readStepIsLocal
@@ -32,3 +31,5 @@ uniqueParameterNodeAtPosition
3231
uniqueParameterNodePosition
3332
uniqueContentApprox
3433
identityLocalStep
34+
missingArgumentCall
35+
multipleArgumentCall

cpp/ql/test/library-tests/dataflow/fields/dataflow-consistency.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ uniqueType
1010
uniqueNodeLocation
1111
missingLocation
1212
uniqueNodeToString
13-
missingToString
1413
parameterCallable
1514
localFlowIsLocal
1615
readStepIsLocal
@@ -192,3 +191,5 @@ uniqueParameterNodeAtPosition
192191
uniqueParameterNodePosition
193192
uniqueContentApprox
194193
identityLocalStep
194+
missingArgumentCall
195+
multipleArgumentCall

cpp/ql/test/library-tests/dataflow/fields/dataflow-ir-consistency.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ uniqueType
44
uniqueNodeLocation
55
missingLocation
66
uniqueNodeToString
7-
missingToString
87
parameterCallable
98
localFlowIsLocal
109
readStepIsLocal
@@ -53,3 +52,5 @@ uniqueParameterNodeAtPosition
5352
uniqueParameterNodePosition
5453
uniqueContentApprox
5554
identityLocalStep
55+
missingArgumentCall
56+
multipleArgumentCall

cpp/ql/test/library-tests/syntax-zoo/dataflow-consistency.expected

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ uniqueNodeLocation
1616
missingLocation
1717
| Nodes without location: 2 |
1818
uniqueNodeToString
19-
missingToString
2019
parameterCallable
2120
localFlowIsLocal
2221
readStepIsLocal
@@ -98,3 +97,5 @@ uniqueParameterNodeAtPosition
9897
uniqueParameterNodePosition
9998
uniqueContentApprox
10099
identityLocalStep
100+
missingArgumentCall
101+
multipleArgumentCall

cpp/ql/test/library-tests/syntax-zoo/dataflow-ir-consistency.expected

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ uniqueNodeLocation
55
missingLocation
66
uniqueNodeToString
77
| cpp11.cpp:50:15:50:16 | (no string representation) | Node should have one toString but has 0. |
8-
missingToString
9-
| Nodes without toString: 1 |
108
parameterCallable
119
localFlowIsLocal
1210
readStepIsLocal
@@ -54,3 +52,5 @@ uniqueParameterNodeAtPosition
5452
uniqueParameterNodePosition
5553
uniqueContentApprox
5654
identityLocalStep
55+
missingArgumentCall
56+
multipleArgumentCall

csharp/ql/consistency-queries/DataFlowConsistency.ql

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

7474
predicate reverseReadExclude(Node n) { n.asExpr() = any(AwaitExpr ae).getExpr() }
75-
}
7675

77-
import MakeConsistency<CsharpDataFlow, CsharpTaintTracking, Input>
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+
}
7887

79-
query predicate multipleToString(DataFlow::Node n, string s) {
80-
s = strictconcat(n.toString(), ",") and
81-
strictcount(n.toString()) > 1
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+
}
82113
}
114+
115+
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. */

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowImplConsistency.qll

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,10 @@ private module Input implements InputSig<PythonDataFlow> {
4747
predicate identityLocalStepExclude(Node n) {
4848
not exists(n.getLocation().getFile().getRelativePath())
4949
}
50+
51+
predicate multipleArgumentCallExclude(ArgumentNode arg, DataFlowCall call) {
52+
isArgumentNode(arg, call, _)
53+
}
5054
}
5155

5256
module Consistency = MakeConsistency<PythonDataFlow, PythonTaintTracking, Input>;

0 commit comments

Comments
 (0)