Skip to content

Commit c952f6a

Browse files
committed
Python: Update rest of tests to new dataflow lib
I had missed these originally, since I had just fixed the ones that were highlighted in the actions logs, thinking they had covered everything :(
1 parent 46531e6 commit c952f6a

File tree

18 files changed

+109
-133
lines changed

18 files changed

+109
-133
lines changed

python/ql/src/meta/alerts/RemoteFlowSourcesReach.ql

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ private import semmle.python.dataflow.new.RemoteFlowSources
1616
private import meta.MetaMetrics
1717
private import semmle.python.dataflow.new.internal.PrintNode
1818

19-
class RemoteFlowSourceReach extends TaintTracking::Configuration {
20-
RemoteFlowSourceReach() { this = "RemoteFlowSourceReach" }
21-
22-
override predicate isSource(DataFlow::Node node) {
19+
module RemoteFlowSourceReachConfig implements DataFlow::ConfigSig {
20+
predicate isSource(DataFlow::Node node) {
2321
node instanceof RemoteFlowSource and
2422
not node.getLocation().getFile() instanceof IgnoredFile
2523
}
2624

27-
override predicate isSink(DataFlow::Node node) {
25+
predicate isSink(DataFlow::Node node) {
2826
not node.getLocation().getFile() instanceof IgnoredFile
2927
// We could try to reduce the number of sinks in this configuration, by only
3028
// allowing something that is on one end of a localFlowStep, readStep or storeStep,
@@ -37,6 +35,8 @@ class RemoteFlowSourceReach extends TaintTracking::Configuration {
3735
}
3836
}
3937

40-
from RemoteFlowSourceReach cfg, DataFlow::Node reachable
41-
where cfg.hasFlow(_, reachable)
38+
module RemoteFlowSourceReachFlow = TaintTracking::Global<RemoteFlowSourceReachConfig>;
39+
40+
from DataFlow::Node reachable
41+
where RemoteFlowSourceReachFlow::flow(_, reachable)
4242
select reachable, prettyNode(reachable)

python/ql/test/experimental/dataflow/TestUtil/DataflowQueryTest.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ module FromTaintTrackingStateConfig<DataFlow::StateConfigSig C> {
104104
import MakeQueryTest<Impl>
105105
}
106106

107-
signature class LegacyConfiguration extends DataFlow::Configuration;
107+
deprecated signature class LegacyConfiguration extends DataFlow::Configuration;
108108

109-
module FromLegacyConfiguration<LegacyConfiguration C> {
109+
deprecated module FromLegacyConfiguration<LegacyConfiguration C> {
110110
module Impl implements QueryTestSig {
111111
predicate isSink(DataFlow::Node sink) { any(C c).isSink(sink) or any(C c).isSink(sink, _) }
112112

python/ql/test/experimental/dataflow/basic/allFlowsConfig.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import semmle.python.dataflow.new.DataFlow
44
* A configuration to find all flows.
55
* To be used on tiny programs.
66
*/
7-
class AllFlowsConfig extends DataFlow::Configuration {
8-
AllFlowsConfig() { this = "AllFlowsConfig" }
7+
module AllFlowsConfig implements DataFlow::ConfigSig {
8+
predicate isSource(DataFlow::Node node) { any() }
99

10-
override predicate isSource(DataFlow::Node node) { any() }
11-
12-
override predicate isSink(DataFlow::Node node) { any() }
10+
predicate isSink(DataFlow::Node node) { any() }
1311
}
12+
13+
module AllFlowsFlow = DataFlow::Global<AllFlowsConfig>;

python/ql/test/experimental/dataflow/basic/global.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import allFlowsConfig
33
from DataFlow::Node source, DataFlow::Node sink
44
where
55
source != sink and
6-
exists(AllFlowsConfig cfg | cfg.hasFlow(source, sink)) and
6+
AllFlowsFlow::flow(source, sink) and
77
exists(source.getLocation().getFile().getRelativePath()) and
88
exists(sink.getLocation().getFile().getRelativePath())
99
select source, sink

python/ql/test/experimental/dataflow/basic/globalStep.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import allFlowsConfig
22

3-
from DataFlow::PathNode fromNode, DataFlow::PathNode toNode
3+
from AllFlowsFlow::PathNode fromNode, AllFlowsFlow::PathNode toNode
44
where
55
toNode = fromNode.getASuccessor() and
66
exists(fromNode.getNode().getLocation().getFile().getRelativePath()) and

python/ql/test/experimental/dataflow/basic/maximalFlows.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import maximalFlowsConfig
33
from DataFlow::Node source, DataFlow::Node sink
44
where
55
source != sink and
6-
exists(MaximalFlowsConfig cfg | cfg.hasFlow(source, sink)) and
6+
MaximalFlowsFlow::flow(source, sink) and
77
exists(source.getLocation().getFile().getRelativePath()) and
88
exists(sink.getLocation().getFile().getRelativePath())
99
select source, sink

python/ql/test/experimental/dataflow/basic/maximalFlowsConfig.qll

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,20 +5,20 @@ private import semmle.python.dataflow.new.internal.DataFlowPrivate as DataFlowPr
55
* A configuration to find all "maximal" flows.
66
* To be used on small programs.
77
*/
8-
class MaximalFlowsConfig extends DataFlow::Configuration {
9-
MaximalFlowsConfig() { this = "AllFlowsConfig" }
10-
11-
override predicate isSource(DataFlow::Node node) {
8+
module MaximalFlowsConfig implements DataFlow::ConfigSig {
9+
predicate isSource(DataFlow::Node node) {
1210
node instanceof DataFlow::ParameterNode
1311
or
1412
node instanceof DataFlow::EssaNode and
1513
not exists(DataFlow::EssaNode pred | DataFlow::localFlowStep(pred, node))
1614
}
1715

18-
override predicate isSink(DataFlow::Node node) {
16+
predicate isSink(DataFlow::Node node) {
1917
node instanceof DataFlowPrivate::ReturnNode
2018
or
2119
node instanceof DataFlow::EssaNode and
2220
not exists(node.(DataFlow::EssaNode).getVar().getASourceUse())
2321
}
2422
}
23+
24+
module MaximalFlowsFlow = DataFlow::Global<MaximalFlowsConfig>;

python/ql/test/experimental/dataflow/basic/sinks.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import allFlowsConfig
22

33
from DataFlow::Node sink
44
where
5-
exists(AllFlowsConfig cfg | cfg.isSink(sink)) and
5+
AllFlowsConfig::isSink(sink) and
66
exists(sink.getLocation().getFile().getRelativePath())
77
select sink

python/ql/test/experimental/dataflow/basic/sources.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ import allFlowsConfig
22

33
from DataFlow::Node source
44
where
5-
exists(AllFlowsConfig cfg | cfg.isSource(source)) and
5+
AllFlowsConfig::isSource(source) and
66
exists(source.getLocation().getFile().getRelativePath())
77
select source

python/ql/test/experimental/dataflow/coverage/argumentRoutingTest.ql

Lines changed: 30 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,11 @@ module Argument1RoutingTest implements RoutingTestSig {
1010

1111
predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink, Argument arg) {
1212
(
13-
exists(Argument1ExtraRoutingConfig cfg | cfg.hasFlow(source, sink))
13+
Argument1ExtraRoutingFlow::flow(source, sink)
1414
or
15-
exists(ArgumentRoutingConfig cfg |
16-
cfg.hasFlow(source, sink) and
17-
cfg.isArgSource(source, 1) and
18-
cfg.isGoodSink(sink, 1)
19-
)
15+
ArgumentRoutingFlow::flow(source, sink) and
16+
ArgumentRoutingConfig::isArgSource(source, 1) and
17+
ArgumentRoutingConfig::isGoodSink(sink, 1)
2018
) and
2119
exists(arg)
2220
}
@@ -26,46 +24,42 @@ class ArgNumber extends int {
2624
ArgNumber() { this in [1 .. 7] }
2725
}
2826

29-
class ArgumentRoutingConfig extends DataFlow::Configuration {
30-
ArgumentRoutingConfig() { this = "ArgumentRoutingConfig" }
31-
32-
predicate isArgSource(DataFlow::Node node, ArgNumber argNumber) {
27+
module ArgumentRoutingConfig implements DataFlow::ConfigSig {
28+
additional predicate isArgSource(DataFlow::Node node, ArgNumber argNumber) {
3329
node.(DataFlow::CfgNode).getNode().(NameNode).getId() = "arg" + argNumber
3430
}
3531

36-
override predicate isSource(DataFlow::Node node) { this.isArgSource(node, _) }
32+
predicate isSource(DataFlow::Node node) { isArgSource(node, _) }
3733

38-
predicate isGoodSink(DataFlow::Node node, ArgNumber argNumber) {
34+
additional predicate isGoodSink(DataFlow::Node node, ArgNumber argNumber) {
3935
exists(CallNode call |
4036
call.getFunction().(NameNode).getId() = "SINK" + argNumber and
4137
node.(DataFlow::CfgNode).getNode() = call.getAnArg()
4238
)
4339
}
4440

45-
predicate isBadSink(DataFlow::Node node, ArgNumber argNumber) {
41+
additional predicate isBadSink(DataFlow::Node node, ArgNumber argNumber) {
4642
exists(CallNode call |
4743
call.getFunction().(NameNode).getId() = "SINK" + argNumber + "_F" and
4844
node.(DataFlow::CfgNode).getNode() = call.getAnArg()
4945
)
5046
}
5147

52-
override predicate isSink(DataFlow::Node node) {
53-
this.isGoodSink(node, _) or this.isBadSink(node, _)
54-
}
48+
predicate isSink(DataFlow::Node node) { isGoodSink(node, _) or isBadSink(node, _) }
5549

5650
/**
5751
* We want to be able to use `arg` in a sequence of calls such as `func(kw=arg); ... ; func(arg)`.
5852
* Use-use flow lets the argument to the first call reach the sink inside the second call,
5953
* making it seem like we handle all cases even if we only handle the last one.
6054
* We make the test honest by preventing flow into source nodes.
6155
*/
62-
override predicate isBarrierIn(DataFlow::Node node) { this.isSource(node) }
56+
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
6357
}
6458

65-
class Argument1ExtraRoutingConfig extends DataFlow::Configuration {
66-
Argument1ExtraRoutingConfig() { this = "Argument1ExtraRoutingConfig" }
59+
module ArgumentRoutingFlow = DataFlow::Global<ArgumentRoutingConfig>;
6760

68-
override predicate isSource(DataFlow::Node node) {
61+
module Argument1ExtraRoutingConfig implements DataFlow::ConfigSig {
62+
predicate isSource(DataFlow::Node node) {
6963
exists(AssignmentDefinition def, DataFlow::CallCfgNode call |
7064
def.getVariable() = node.(DataFlow::EssaNode).getVar() and
7165
def.getValue() = call.getNode() and
@@ -74,7 +68,7 @@ class Argument1ExtraRoutingConfig extends DataFlow::Configuration {
7468
node.(DataFlow::EssaNode).getVar().getName().matches("with\\_%")
7569
}
7670

77-
override predicate isSink(DataFlow::Node node) {
71+
predicate isSink(DataFlow::Node node) {
7872
exists(CallNode call |
7973
call.getFunction().(NameNode).getId() = "SINK1" and
8074
node.(DataFlow::CfgNode).getNode() = call.getAnArg()
@@ -87,20 +81,20 @@ class Argument1ExtraRoutingConfig extends DataFlow::Configuration {
8781
* making it seem like we handle all cases even if we only handle the last one.
8882
* We make the test honest by preventing flow into source nodes.
8983
*/
90-
override predicate isBarrierIn(DataFlow::Node node) { this.isSource(node) }
84+
predicate isBarrierIn(DataFlow::Node node) { isSource(node) }
9185
}
9286

87+
module Argument1ExtraRoutingFlow = DataFlow::Global<Argument1ExtraRoutingConfig>;
88+
9389
module RestArgumentRoutingTest implements RoutingTestSig {
9490
class Argument = ArgNumber;
9591

9692
string flowTag(Argument arg) { result = "arg" + arg }
9793

9894
predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink, Argument arg) {
99-
exists(ArgumentRoutingConfig cfg |
100-
cfg.hasFlow(source, sink) and
101-
cfg.isArgSource(source, arg) and
102-
cfg.isGoodSink(sink, arg)
103-
) and
95+
ArgumentRoutingFlow::flow(source, sink) and
96+
ArgumentRoutingConfig::isArgSource(source, arg) and
97+
ArgumentRoutingConfig::isGoodSink(sink, arg) and
10498
arg > 1
10599
}
106100
}
@@ -112,11 +106,9 @@ module BadArgumentRoutingTestSinkF implements RoutingTestSig {
112106
string flowTag(Argument arg) { result = "bad" + arg }
113107

114108
predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink, Argument arg) {
115-
exists(ArgumentRoutingConfig cfg |
116-
cfg.hasFlow(source, sink) and
117-
cfg.isArgSource(source, arg) and
118-
cfg.isBadSink(sink, arg)
119-
)
109+
ArgumentRoutingFlow::flow(source, sink) and
110+
ArgumentRoutingConfig::isArgSource(source, arg) and
111+
ArgumentRoutingConfig::isBadSink(sink, arg)
120112
}
121113
}
122114

@@ -127,14 +119,12 @@ module BadArgumentRoutingTestWrongSink implements RoutingTestSig {
127119
string flowTag(Argument arg) { result = "bad" + arg }
128120

129121
predicate relevantFlow(DataFlow::Node source, DataFlow::Node sink, Argument arg) {
130-
exists(ArgumentRoutingConfig cfg |
131-
cfg.hasFlow(source, sink) and
132-
cfg.isArgSource(source, any(ArgNumber i | not i = arg)) and
133-
(
134-
cfg.isGoodSink(sink, arg)
135-
or
136-
cfg.isBadSink(sink, arg)
137-
)
122+
ArgumentRoutingFlow::flow(source, sink) and
123+
ArgumentRoutingConfig::isArgSource(source, any(ArgNumber i | not i = arg)) and
124+
(
125+
ArgumentRoutingConfig::isGoodSink(sink, arg)
126+
or
127+
ArgumentRoutingConfig::isBadSink(sink, arg)
138128
)
139129
}
140130
}

0 commit comments

Comments
 (0)