mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Python: refactor test for global flow
This commit is contained in:
19
python/ql/test/experimental/dataflow/allFlowsConfig.qll
Normal file
19
python/ql/test/experimental/dataflow/allFlowsConfig.qll
Normal file
@@ -0,0 +1,19 @@
|
||||
import experimental.dataflow.DataFlow
|
||||
|
||||
/**
|
||||
* A configuration to find "all" flows.
|
||||
* To be used on small programs.
|
||||
*/
|
||||
class AllFlowsConfig extends DataFlow::Configuration {
|
||||
AllFlowsConfig() { this = "AllFlowsConfig" }
|
||||
|
||||
override predicate isSource(DataFlow::Node node) {
|
||||
node.asCfgNode() instanceof CallNode
|
||||
}
|
||||
|
||||
override predicate isSink(DataFlow::Node node) {
|
||||
not exists(DataFlow::Node succ |
|
||||
DataFlow::localFlowStep(node, succ)
|
||||
)
|
||||
}
|
||||
}
|
||||
@@ -1,36 +1,9 @@
|
||||
import python
|
||||
import experimental.dataflow.DataFlow
|
||||
|
||||
class SimpleConfig extends DataFlow::Configuration {
|
||||
SimpleConfig() { this = "SimpleConfig" }
|
||||
|
||||
// TODO: make a test out of this
|
||||
override predicate isSource(DataFlow::Node node) {
|
||||
node.asEssaNode() instanceof EssaNodeDefinition
|
||||
}
|
||||
|
||||
// TODO: make a test out of this
|
||||
override predicate isSink(DataFlow::Node node) {
|
||||
not exists(EssaDefinition succ |
|
||||
node.asEssaNode().getDefinition() = pred(succ)
|
||||
)
|
||||
}
|
||||
|
||||
EssaDefinition pred(EssaDefinition n) {
|
||||
// result = value(n.(EssaNodeDefinition))
|
||||
// or
|
||||
result = n.(EssaNodeRefinement).getInput()
|
||||
or
|
||||
result = n.(EssaEdgeRefinement).getInput()
|
||||
or
|
||||
result = n.(PhiFunction).getShortCircuitInput()
|
||||
}
|
||||
}
|
||||
import allFlowsConfig
|
||||
|
||||
from
|
||||
DataFlow::Node source,
|
||||
DataFlow::Node sink
|
||||
where
|
||||
exists(SimpleConfig cfg | cfg.hasFlow(source, sink))
|
||||
exists(AllFlowsConfig cfg | cfg.hasFlow(source, sink))
|
||||
select
|
||||
source, sink
|
||||
source, sink
|
||||
|
||||
28
python/ql/test/experimental/dataflow/sinks.expected
Normal file
28
python/ql/test/experimental/dataflow/sinks.expected
Normal file
@@ -0,0 +1,28 @@
|
||||
| test.py:0:0:0:0 | Entry node for Module test |
|
||||
| test.py:0:0:0:0 | Exit node for Module test |
|
||||
| test.py:0:0:0:0 | GSSA Variable __name__ |
|
||||
| test.py:0:0:0:0 | GSSA Variable __package__ |
|
||||
| test.py:0:0:0:0 | GSSA Variable c |
|
||||
| test.py:0:0:0:0 | SSA variable $ |
|
||||
| test.py:1:1:1:1 | ControlFlowNode for a |
|
||||
| test.py:2:1:2:1 | ControlFlowNode for b |
|
||||
| test.py:2:1:2:1 | GSSA Variable b |
|
||||
| test.py:4:1:4:9 | Entry node for Function f |
|
||||
| test.py:4:1:4:9 | Exit node for Function f |
|
||||
| test.py:4:5:4:5 | ControlFlowNode for f |
|
||||
| test.py:4:5:4:5 | GSSA Variable f |
|
||||
| test.py:4:7:4:7 | ControlFlowNode for x |
|
||||
| test.py:4:7:4:7 | SSA variable x |
|
||||
| test.py:5:3:5:3 | ControlFlowNode for y |
|
||||
| test.py:5:3:5:3 | SSA variable y |
|
||||
| test.py:5:7:5:7 | ControlFlowNode for x |
|
||||
| test.py:5:11:5:11 | ControlFlowNode for IntegerLiteral |
|
||||
| test.py:6:3:6:14 | ControlFlowNode for Return |
|
||||
| test.py:6:10:6:10 | ControlFlowNode for y |
|
||||
| test.py:6:10:6:14 | ControlFlowNode for BinaryExpr |
|
||||
| test.py:6:14:6:14 | ControlFlowNode for IntegerLiteral |
|
||||
| test.py:8:1:8:1 | ControlFlowNode for c |
|
||||
| test.py:8:1:8:1 | GSSA Variable c |
|
||||
| test.py:8:5:8:5 | ControlFlowNode for f |
|
||||
| test.py:8:5:8:8 | GSSA Variable a |
|
||||
| test.py:8:7:8:7 | ControlFlowNode for a |
|
||||
5
python/ql/test/experimental/dataflow/sinks.ql
Normal file
5
python/ql/test/experimental/dataflow/sinks.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import allFlowsConfig
|
||||
|
||||
from DataFlow::Node sink
|
||||
where exists(AllFlowsConfig cfg | cfg.isSink(sink))
|
||||
select sink
|
||||
1
python/ql/test/experimental/dataflow/sources.expected
Normal file
1
python/ql/test/experimental/dataflow/sources.expected
Normal file
@@ -0,0 +1 @@
|
||||
| test.py:8:5:8:8 | ControlFlowNode for f() |
|
||||
5
python/ql/test/experimental/dataflow/sources.ql
Normal file
5
python/ql/test/experimental/dataflow/sources.ql
Normal file
@@ -0,0 +1,5 @@
|
||||
import allFlowsConfig
|
||||
|
||||
from DataFlow::Node source
|
||||
where exists(AllFlowsConfig cfg | cfg.isSource(source))
|
||||
select source
|
||||
Reference in New Issue
Block a user