Skip to content

Commit d182eae

Browse files
committed
Python: Add consistency check for PhaseDependentFlow
This would have found the problem in github#15755. As highlighted in the comment in the code, it's not a perfect solution since we don't have an automatic way to ensure we don't introduce a new PhaseDependentFlow use with a new step relation and forget to add it to this consistency check... but I think this consistency check still adds value!
1 parent 664dac6 commit d182eae

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
private import python
2+
private import semmle.python.dataflow.new.DataFlow::DataFlow
3+
private import semmle.python.dataflow.new.internal.DataFlowPrivate as DataFlowPrivate
4+
private import semmle.python.dataflow.new.internal.VariableCapture as VariableCapture
5+
6+
from Node node
7+
where
8+
not exists(node.getScope()) and
9+
exists(Node nodeFrom, Node nodeTo | node in [nodeFrom, nodeTo] |
10+
// the list of step relations used with PhaseDependentFlow has been compiled
11+
// manually, and there isn't really a good way to do so manually :|
12+
DataFlowPrivate::LocalFlow::definitionFlowStep(nodeFrom, nodeTo)
13+
or
14+
DataFlowPrivate::LocalFlow::expressionFlowStep(nodeFrom, nodeTo)
15+
or
16+
DataFlowPrivate::LocalFlow::useUseFlowStep(nodeFrom, nodeTo)
17+
or
18+
VariableCapture::valueStep(nodeFrom, nodeTo)
19+
)
20+
select node,
21+
"Node being used in PhaseDependentFlow does not have result for .getScope(), so will not work properly (since division into run-time/import-time is based on .getScope result)"

0 commit comments

Comments
 (0)