Skip to content

Commit a55b466

Browse files
committed
Python: support for with-definitions
1 parent e8289d6 commit a55b466

3 files changed

Lines changed: 14 additions & 1 deletion

File tree

python/ql/src/experimental/dataflow/internal/DataFlowPrivate.qll

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,19 @@ module EssaFlow {
4242
// nodeTo is `x`, essa var
4343
nodeFrom.asCfgNode() = nodeTo.asEssaNode().getDefinition().(AssignmentDefinition).getValue()
4444
or
45+
// With definition
46+
// `with f(42) as x:`
47+
// nodeFrom is `f(42)`, cfg node
48+
// nodeTo is `x`, essa var
49+
exists(With with, ControlFlowNode contextManager, ControlFlowNode var |
50+
nodeFrom.asCfgNode() = contextManager and
51+
nodeTo.asEssaNode().getDefinition().(WithDefinition).getDefiningNode() = var and
52+
// see `with_flow`
53+
with.getContextExpr() = contextManager.getNode() and
54+
with.getOptionalVars() = var.getNode() and
55+
contextManager.strictlyDominates(var)
56+
)
57+
or
4558
// Use
4659
// `y = 42`
4760
// `x = f(y)`

python/ql/test/experimental/dataflow/regression/dataflow.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
| test.py:37:13:37:18 | ControlFlowNode for SOURCE | test.py:41:14:41:14 | ControlFlowNode for t |
77
| test.py:76:9:76:14 | ControlFlowNode for SOURCE | test.py:78:10:78:10 | ControlFlowNode for t |
88
| test.py:108:13:108:18 | ControlFlowNode for SOURCE | test.py:112:14:112:14 | ControlFlowNode for t |
9+
| test.py:139:10:139:15 | ControlFlowNode for SOURCE | test.py:140:14:140:14 | ControlFlowNode for t |
910
| test.py:143:9:143:14 | ControlFlowNode for SOURCE | test.py:145:10:145:10 | ControlFlowNode for s |
1011
| test.py:158:9:158:14 | ControlFlowNode for SOURCE | test.py:160:14:160:14 | ControlFlowNode for t |
1112
| test.py:158:9:158:14 | ControlFlowNode for SOURCE | test.py:162:14:162:14 | ControlFlowNode for t |

python/ql/test/experimental/dataflow/regression/dataflow.ql

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ from
44
DataFlow::Node source,
55
DataFlow::Node sink
66
where
7-
// source != sink and
87
exists(TestConfiguration cfg | cfg.hasFlow(source, sink))
98
select
109
source, sink

0 commit comments

Comments
 (0)