Skip to content

Commit b8d6f76

Browse files
authored
Merge pull request #4056 from yoff/SharedDataflow_ParameterTests
Python: Shared dataflow, parameter routing tests
2 parents a93a84f + 2817602 commit b8d6f76

File tree

11 files changed

+460
-75
lines changed

11 files changed

+460
-75
lines changed

python/ql/test/experimental/dataflow/coverage/argumentRouting1.expected

Whitespace-only changes.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import experimental.dataflow.DataFlow
2+
3+
/**
4+
* A configuration to check routing of arguments through magic methods.
5+
*/
6+
class ArgumentRoutingConfig extends DataFlow::Configuration {
7+
ArgumentRoutingConfig() { this = "ArgumentRoutingConfig" }
8+
9+
override predicate isSource(DataFlow::Node node) {
10+
exists(AssignmentDefinition def |
11+
def.getVariable() = node.(DataFlow::EssaNode).getVar() and
12+
def.getValue().(DataFlow::DataFlowCall).getCallable().getName().matches("With\\_%")
13+
) and
14+
node.(DataFlow::EssaNode).getVar().getName().matches("with\\_%")
15+
}
16+
17+
override predicate isSink(DataFlow::Node node) {
18+
exists(CallNode call |
19+
call.getFunction().(NameNode).getId() = "SINK1" and
20+
node.(DataFlow::CfgNode).getNode() = call.getAnArg()
21+
)
22+
}
23+
}
24+
25+
from DataFlow::Node source, DataFlow::Node sink
26+
where
27+
source.getLocation().getFile().getBaseName() = "classes.py" and
28+
sink.getLocation().getFile().getBaseName() = "classes.py" and
29+
exists(ArgumentRoutingConfig cfg | cfg.hasFlow(source, sink))
30+
select source, sink

python/ql/test/experimental/dataflow/coverage/argumentRouting2.expected

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import experimental.dataflow.DataFlow
2+
3+
/**
4+
* A configuration to check routing of arguments through magic methods.
5+
*/
6+
class ArgumentRoutingConfig extends DataFlow::Configuration {
7+
ArgumentRoutingConfig() { this = "ArgumentRoutingConfig" }
8+
9+
override predicate isSource(DataFlow::Node node) {
10+
node.(DataFlow::CfgNode).getNode().(NameNode).getId() = "arg2"
11+
}
12+
13+
override predicate isSink(DataFlow::Node node) {
14+
exists(CallNode call |
15+
call.getFunction().(NameNode).getId() = "SINK2" and
16+
node.(DataFlow::CfgNode).getNode() = call.getAnArg()
17+
)
18+
}
19+
}
20+
21+
from DataFlow::Node source, DataFlow::Node sink
22+
where
23+
source.getLocation().getFile().getBaseName() = "classes.py" and
24+
sink.getLocation().getFile().getBaseName() = "classes.py" and
25+
exists(ArgumentRoutingConfig cfg | cfg.hasFlow(source, sink))
26+
select source, sink

python/ql/test/experimental/dataflow/coverage/argumentRouting3.expected

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import experimental.dataflow.DataFlow
2+
3+
/**
4+
* A configuration to check routing of arguments through magic methods.
5+
*/
6+
class ArgumentRoutingConfig extends DataFlow::Configuration {
7+
ArgumentRoutingConfig() { this = "ArgumentRoutingConfig" }
8+
9+
override predicate isSource(DataFlow::Node node) {
10+
node.(DataFlow::CfgNode).getNode().(NameNode).getId() = "arg3"
11+
}
12+
13+
override predicate isSink(DataFlow::Node node) {
14+
exists(CallNode call |
15+
call.getFunction().(NameNode).getId() = "SINK3" and
16+
node.(DataFlow::CfgNode).getNode() = call.getAnArg()
17+
)
18+
}
19+
}
20+
21+
from DataFlow::Node source, DataFlow::Node sink
22+
where
23+
source.getLocation().getFile().getBaseName() = "classes.py" and
24+
sink.getLocation().getFile().getBaseName() = "classes.py" and
25+
exists(ArgumentRoutingConfig cfg | cfg.hasFlow(source, sink))
26+
select source, sink

python/ql/test/experimental/dataflow/coverage/argumentRouting4.expected

Whitespace-only changes.
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import experimental.dataflow.DataFlow
2+
3+
/**
4+
* A configuration to check routing of arguments through magic methods.
5+
*/
6+
class ArgumentRoutingConfig extends DataFlow::Configuration {
7+
ArgumentRoutingConfig() { this = "ArgumentRoutingConfig" }
8+
9+
override predicate isSource(DataFlow::Node node) {
10+
node.(DataFlow::CfgNode).getNode().(NameNode).getId() = "arg4"
11+
}
12+
13+
override predicate isSink(DataFlow::Node node) {
14+
exists(CallNode call |
15+
call.getFunction().(NameNode).getId() = "SINK4" and
16+
node.(DataFlow::CfgNode).getNode() = call.getAnArg()
17+
)
18+
}
19+
}
20+
21+
from DataFlow::Node source, DataFlow::Node sink
22+
where
23+
source.getLocation().getFile().getBaseName() = "classes.py" and
24+
sink.getLocation().getFile().getBaseName() = "classes.py" and
25+
exists(ArgumentRoutingConfig cfg | cfg.hasFlow(source, sink))
26+
select source, sink

0 commit comments

Comments
 (0)