Skip to content

Commit c787bb2

Browse files
committed
C#: Re-factor the callablereturnarg tests.
1 parent 9c5b8e2 commit c787bb2

File tree

3 files changed

+29
-37
lines changed

3 files changed

+29
-37
lines changed

csharp/ql/test/library-tests/dataflow/callablereturnsarg/Common.qll

Lines changed: 23 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,34 +10,38 @@ private predicate outRefDef(DataFlow::ExprNode ne, int outRef) {
1010
)
1111
}
1212

13-
class Configuration extends DataFlow::Configuration {
14-
Configuration() { this = "Configuration" }
13+
module Config implements DataFlow::ConfigSig {
14+
predicate isSource(DataFlow::Node source) { source instanceof DataFlow::ParameterNode }
1515

16-
override predicate isSource(DataFlow::Node source) { source instanceof DataFlow::ParameterNode }
17-
18-
override predicate isSink(DataFlow::Node sink) {
16+
predicate isSink(DataFlow::Node sink) {
1917
any(Callable c).canReturn(sink.asExpr()) or outRefDef(sink, _)
2018
}
2119

22-
override predicate isBarrier(DataFlow::Node node) {
20+
predicate isBarrier(DataFlow::Node node) {
2321
exists(AbstractValues::NullValue nv | node.(GuardedDataFlowNode).mustHaveValue(nv) |
2422
nv.isNull()
2523
)
2624
}
2725
}
2826

29-
predicate flowOutFromParameter(DataFlow::Configuration c, Parameter p) {
30-
exists(DataFlow::ExprNode ne, DataFlow::ParameterNode np |
31-
p.getCallable().canReturn(ne.getExpr()) and
32-
np.getParameter() = p and
33-
c.hasFlow(np, ne)
34-
)
35-
}
27+
module FlowOut<DataFlow::GlobalFlowSig Input> {
28+
predicate flowOutFromParameter(Parameter p) {
29+
exists(DataFlow::ExprNode ne, DataFlow::ParameterNode np |
30+
p.getCallable().canReturn(ne.getExpr()) and
31+
np.getParameter() = p and
32+
Input::flow(np, ne)
33+
)
34+
}
3635

37-
predicate flowOutFromParameterOutOrRef(DataFlow::Configuration c, Parameter p, int outRef) {
38-
exists(DataFlow::ExprNode ne, DataFlow::ParameterNode np |
39-
outRefDef(ne, outRef) and
40-
np.getParameter() = p and
41-
c.hasFlow(np, ne)
42-
)
36+
predicate flowOutFromParameterOutOrRef(Parameter p, int outRef) {
37+
exists(DataFlow::ExprNode ne, DataFlow::ParameterNode np |
38+
outRefDef(ne, outRef) and
39+
np.getParameter() = p and
40+
Input::flow(np, ne)
41+
)
42+
}
4343
}
44+
45+
module Data = FlowOut<DataFlow::Global<Config>>;
46+
47+
module Taint = FlowOut<TaintTracking::Global<Config>>;
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import csharp
22
import Common
33

4-
from Configuration c, Parameter p, int outRefArg
4+
from Parameter p, int outRefArg
55
where
6-
flowOutFromParameter(c, p) and outRefArg = -1
6+
Data::flowOutFromParameter(p) and outRefArg = -1
77
or
8-
flowOutFromParameterOutOrRef(c, p, outRefArg)
8+
Data::flowOutFromParameterOutOrRef(p, outRefArg)
99
select p.getCallable(), p.getPosition(), outRefArg
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
11
import csharp
22
import Common
33

4-
class TaintTrackingConfiguration extends TaintTracking::Configuration {
5-
Configuration c;
6-
7-
TaintTrackingConfiguration() { this = "Taint " + c }
8-
9-
override predicate isSource(DataFlow::Node source) { c.isSource(source) }
10-
11-
override predicate isSink(DataFlow::Node sink) { c.isSink(sink) }
12-
13-
override predicate isSanitizer(DataFlow::Node node) { c.isBarrier(node) }
14-
}
15-
16-
from TaintTrackingConfiguration c, Parameter p, int outRefArg
4+
from Parameter p, int outRefArg
175
where
18-
flowOutFromParameter(c, p) and outRefArg = -1
6+
Taint::flowOutFromParameter(p) and outRefArg = -1
197
or
20-
flowOutFromParameterOutOrRef(c, p, outRefArg)
8+
Taint::flowOutFromParameterOutOrRef(p, outRefArg)
219
select p.getCallable(), p.getPosition(), outRefArg

0 commit comments

Comments
 (0)