Skip to content

Commit c13a8e4

Browse files
committed
Data flow: Add more consistency checks
1 parent d6e143a commit c13a8e4

File tree

3 files changed

+31
-17
lines changed

3 files changed

+31
-17
lines changed

csharp/ql/consistency-queries/DataFlowConsistency.ql

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -75,8 +75,3 @@ private module Input implements InputSig<CsharpDataFlow> {
7575
}
7676

7777
import MakeConsistency<CsharpDataFlow, CsharpTaintTracking, Input>
78-
79-
query predicate multipleToString(DataFlow::Node n, string s) {
80-
s = strictconcat(n.toString(), ",") and
81-
strictcount(n.toString()) > 1
82-
}

ruby/ql/consistency-queries/DataFlowConsistency.ql

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,11 @@ private module Input implements InputSig<RubyDataFlow> {
3535
n.asExpr() = arg
3636
)
3737
}
38+
39+
predicate multipleArgumentCallExclude(ArgumentNode arg, DataFlowCall call) {
40+
arg.asExpr().getASuccessor(any(SuccessorTypes::ConditionalSuccessor c)).getASuccessor() =
41+
call.asCall()
42+
}
3843
}
3944

4045
import MakeConsistency<RubyDataFlow, RubyTaintTracking, Input>
41-
42-
query predicate multipleToString(DataFlow::Node n, string s) {
43-
s = strictconcat(n.toString(), ",") and
44-
strictcount(n.toString()) > 1
45-
}

shared/dataflow/codeql/dataflow/internal/DataFlowImplConsistency.qll

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,16 @@ signature module InputSig<DF::InputSig DataFlowLang> {
5858

5959
/** Holds if `n` should be excluded from the consistency test `identityLocalStep`. */
6060
default predicate identityLocalStepExclude(DataFlowLang::Node n) { none() }
61+
62+
/** Holds if `arg` should be excluded from the consistency test `missingArgumentCall`. */
63+
default predicate missingArgumentCallExclude(DataFlowLang::ArgumentNode arg) { none() }
64+
65+
/** Holds if `(arg, call)` should be excluded from the consistency test `multipleArgumentCall`. */
66+
default predicate multipleArgumentCallExclude(
67+
DataFlowLang::ArgumentNode arg, DataFlowLang::DataFlowCall call
68+
) {
69+
none()
70+
}
6171
}
6272

6373
module MakeConsistency<
@@ -147,13 +157,6 @@ module MakeConsistency<
147157
)
148158
}
149159

150-
query predicate missingToString(string msg) {
151-
exists(int c |
152-
c = strictcount(Node n | not exists(n.toString())) and
153-
msg = "Nodes without toString: " + c
154-
)
155-
}
156-
157160
query predicate parameterCallable(ParameterNode p, string msg) {
158161
exists(DataFlowCallable c | isParameterNode(p, c, _) and c != nodeGetEnclosingCallable(p)) and
159162
msg = "Callable mismatch for parameter."
@@ -287,4 +290,20 @@ module MakeConsistency<
287290
not Input::identityLocalStepExclude(n) and
288291
msg = "Node steps to itself"
289292
}
293+
294+
query predicate missingArgumentCall(ArgumentNode arg, string msg) {
295+
not Input::missingArgumentCallExclude(arg) and
296+
not isArgumentNode(arg, _, _) and
297+
msg = "Missing call for argument node."
298+
}
299+
300+
query predicate multipleArgumentCall(ArgumentNode arg, DataFlowCall call, string msg) {
301+
isArgumentNode(arg, call, _) and
302+
not Input::multipleArgumentCallExclude(arg, call) and
303+
strictcount(DataFlowCall call0 |
304+
isArgumentNode(arg, call0, _) and
305+
not Input::multipleArgumentCallExclude(arg, call0)
306+
) > 1 and
307+
msg = "Multiple calls for argument node."
308+
}
290309
}

0 commit comments

Comments
 (0)