Skip to content

Commit 7bb9aeb

Browse files
yoffCopilot
andcommitted
Python: fix library-test compile errors and rebless after CFG migration
Library-test compile fixes after the shared-CFG migration: - PointsTo/global, PointsTo/local: use `f.getNode() = s.getValue()` instead of `s.getValue().getAFlowNode() = f` (the new CFG does not surface getAFlowNode on AST nodes). - PointsTo/new/ImpliesDataflow: bridge new Cfg::ControlFlowNode to the legacy ControlFlowNodeWithPointsTo via AST identity. - frameworks/aiohttp + frameworks/modeling-example: qualify CallNode / NameNode / AttrNode casts with Cfg:: now that those names live in the new CFG facade. Rebless 4 expected files for toString-only differences (renamed CFG positions like 'CFG node for foo' vs 'foo' — no semantic change): ImpliesDataflow, EnclosingCallable, NaiveModel, ProperModel. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent b551863 commit 7bb9aeb

11 files changed

Lines changed: 159 additions & 152 deletions

File tree

python/ql/test/library-tests/PointsTo/global/Global.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@ private import LegacyPointsTo
33

44
from ControlFlowNode f, PointsToContext ctx, Value obj, ControlFlowNode orig
55
where
6-
exists(ExprStmt s | s.getValue().getAFlowNode() = f) and
6+
exists(ExprStmt s | f.getNode() = s.getValue()) and
77
PointsTo::pointsTo(f, ctx, obj, orig)
88
select ctx, f, obj.toString(), orig

python/ql/test/library-tests/PointsTo/local/LocalPointsTo.ql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,6 @@ import semmle.python.objects.ObjectInternal
44

55
from ControlFlowNode f, ObjectInternal obj, ControlFlowNode orig
66
where
7-
exists(ExprStmt s | s.getValue().getAFlowNode() = f) and
7+
exists(ExprStmt s | f.getNode() = s.getValue()) and
88
PointsTo::pointsTo(f, _, obj, orig)
99
select f, obj.toString(), orig
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
| code/h_classes.py:3:1:3:16 | ControlFlowNode for ClassExpr | code/h_classes.py:10:1:10:9 | ControlFlowNode for type() |
2-
| code/h_classes.py:3:1:3:16 | ControlFlowNode for ClassExpr | code/h_classes.py:15:5:15:13 | ControlFlowNode for type() |
3-
| code/l_calls.py:12:1:12:20 | ControlFlowNode for ClassExpr | code/l_calls.py:16:16:16:18 | ControlFlowNode for cls |
4-
| code/l_calls.py:12:1:12:20 | ControlFlowNode for ClassExpr | code/l_calls.py:24:13:24:22 | ControlFlowNode for Attribute() |
5-
| code/l_calls.py:12:1:12:20 | ControlFlowNode for ClassExpr | code/l_calls.py:25:16:25:16 | ControlFlowNode for a |
6-
| code/t_type.py:3:1:3:16 | ControlFlowNode for ClassExpr | code/t_type.py:6:1:6:9 | ControlFlowNode for type() |
7-
| code/t_type.py:3:1:3:16 | ControlFlowNode for ClassExpr | code/t_type.py:13:5:13:13 | ControlFlowNode for type() |
1+
| code/h_classes.py:3:1:3:16 | After ClassExpr | code/h_classes.py:10:1:10:9 | After type() |
2+
| code/h_classes.py:3:1:3:16 | After ClassExpr | code/h_classes.py:15:5:15:13 | After type() |
3+
| code/l_calls.py:12:1:12:20 | After ClassExpr | code/l_calls.py:16:16:16:18 | cls |
4+
| code/l_calls.py:12:1:12:20 | After ClassExpr | code/l_calls.py:24:13:24:22 | After Attribute() |
5+
| code/l_calls.py:12:1:12:20 | After ClassExpr | code/l_calls.py:25:16:25:16 | a |
6+
| code/t_type.py:3:1:3:16 | After ClassExpr | code/t_type.py:6:1:6:9 | After type() |
7+
| code/t_type.py:3:1:3:16 | After ClassExpr | code/t_type.py:13:5:13:13 | After type() |

python/ql/test/library-tests/PointsTo/new/ImpliesDataflow.ql

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,11 @@ private import LegacyPointsTo
88
import semmle.python.dataflow.new.DataFlow
99

1010
predicate pointsToOrigin(DataFlow::CfgNode pointer, DataFlow::CfgNode origin) {
11-
origin.getNode() = pointer.getNode().(ControlFlowNodeWithPointsTo).pointsTo().getOrigin()
11+
exists(ControlFlowNodeWithPointsTo legacyPointer, ControlFlowNode legacyOrigin |
12+
legacyPointer.getNode() = pointer.getNode().getNode() and
13+
legacyOrigin = legacyPointer.pointsTo().getOrigin() and
14+
legacyOrigin.getNode() = origin.getNode().getNode()
15+
)
1216
}
1317

1418
module PointsToConfig implements DataFlow::ConfigSig {

python/ql/test/library-tests/dataflow/enclosing-callable/EnclosingCallable.expected

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
| generator.py:1:1:1:23 | Function generator_func | generator.py:2:24:2:25 | xs |
2020
| generator.py:2:12:2:26 | Function listcomp | generator.py:2:12:2:26 | .0 |
2121
| generator.py:2:12:2:26 | Function listcomp | generator.py:2:12:2:26 | After .0 [empty] |
22-
| generator.py:2:12:2:26 | Function listcomp | generator.py:2:12:2:26 | After .0 [non-empty] |
2322
| generator.py:2:12:2:26 | Function listcomp | generator.py:2:13:2:13 | After Yield |
2423
| generator.py:2:12:2:26 | Function listcomp | generator.py:2:13:2:13 | x |
2524
| generator.py:2:12:2:26 | Function listcomp | generator.py:2:19:2:19 | x |

python/ql/test/library-tests/frameworks/aiohttp/InlineTaintTest.ql

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
import experimental.meta.InlineTaintTest
2+
private import semmle.python.controlflow.internal.Cfg as Cfg
23

3-
predicate isSafe(DataFlow::GuardNode g, ControlFlowNode node, boolean branch) {
4-
g.(CallNode).getFunction().(NameNode).getId() = "is_safe" and
5-
node = g.(CallNode).getArg(_) and
4+
predicate isSafe(DataFlow::GuardNode g, Cfg::ControlFlowNode node, boolean branch) {
5+
g.(Cfg::CallNode).getFunction().(Cfg::NameNode).getId() = "is_safe" and
6+
node = g.(Cfg::CallNode).getArg(_) and
67
branch = true
78
}
89

Lines changed: 42 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,46 @@
11
edges
2-
| test.py:21:11:21:18 | ControlFlowNode for source() | test.py:22:10:22:24 | ControlFlowNode for Attribute() | provenance | AdditionalTaintStep |
3-
| test.py:29:11:29:18 | ControlFlowNode for source() | test.py:32:5:32:7 | ControlFlowNode for val | provenance | AdditionalTaintStep |
4-
| test.py:32:5:32:7 | ControlFlowNode for val | test.py:33:10:33:12 | ControlFlowNode for val | provenance | |
5-
| test.py:40:5:40:7 | ControlFlowNode for val | test.py:41:10:41:12 | ControlFlowNode for val | provenance | |
6-
| test.py:40:11:40:25 | ControlFlowNode for Attribute() | test.py:40:5:40:7 | ControlFlowNode for val | provenance | |
7-
| test.py:45:11:45:18 | ControlFlowNode for source() | test.py:40:11:40:25 | ControlFlowNode for Attribute() | provenance | AdditionalTaintStep |
8-
| test.py:53:5:53:7 | ControlFlowNode for val | test.py:54:10:54:12 | ControlFlowNode for val | provenance | |
9-
| test.py:53:11:53:25 | ControlFlowNode for Attribute() | test.py:53:5:53:7 | ControlFlowNode for val | provenance | |
10-
| test.py:70:11:70:18 | ControlFlowNode for source() | test.py:53:11:53:25 | ControlFlowNode for Attribute() | provenance | AdditionalTaintStep |
11-
| test.py:78:5:78:7 | ControlFlowNode for val | test.py:79:10:79:12 | ControlFlowNode for val | provenance | |
12-
| test.py:78:11:78:14 | ControlFlowNode for bm() | test.py:78:5:78:7 | ControlFlowNode for val | provenance | |
13-
| test.py:83:11:83:18 | ControlFlowNode for source() | test.py:78:11:78:14 | ControlFlowNode for bm() | provenance | AdditionalTaintStep |
14-
| test.py:90:5:90:7 | ControlFlowNode for val | test.py:91:10:91:12 | ControlFlowNode for val | provenance | |
15-
| test.py:90:11:90:14 | ControlFlowNode for bm() | test.py:90:5:90:7 | ControlFlowNode for val | provenance | |
16-
| test.py:107:11:107:18 | ControlFlowNode for source() | test.py:90:11:90:14 | ControlFlowNode for bm() | provenance | AdditionalTaintStep |
2+
| test.py:21:11:21:18 | After source() | test.py:22:10:22:24 | After Attribute() | provenance | AdditionalTaintStep |
3+
| test.py:29:11:29:18 | After source() | test.py:32:5:32:7 | val | provenance | AdditionalTaintStep |
4+
| test.py:32:5:32:7 | val | test.py:33:10:33:12 | val | provenance | |
5+
| test.py:40:5:40:7 | val | test.py:41:10:41:12 | val | provenance | |
6+
| test.py:40:11:40:25 | After Attribute() | test.py:40:5:40:7 | val | provenance | |
7+
| test.py:45:11:45:18 | After source() | test.py:40:11:40:25 | After Attribute() | provenance | AdditionalTaintStep |
8+
| test.py:53:5:53:7 | val | test.py:54:10:54:12 | val | provenance | |
9+
| test.py:53:11:53:25 | After Attribute() | test.py:53:5:53:7 | val | provenance | |
10+
| test.py:70:11:70:18 | After source() | test.py:53:11:53:25 | After Attribute() | provenance | AdditionalTaintStep |
11+
| test.py:78:5:78:7 | val | test.py:79:10:79:12 | val | provenance | |
12+
| test.py:78:11:78:14 | After bm() | test.py:78:5:78:7 | val | provenance | |
13+
| test.py:83:11:83:18 | After source() | test.py:78:11:78:14 | After bm() | provenance | AdditionalTaintStep |
14+
| test.py:90:5:90:7 | val | test.py:91:10:91:12 | val | provenance | |
15+
| test.py:90:11:90:14 | After bm() | test.py:90:5:90:7 | val | provenance | |
16+
| test.py:107:11:107:18 | After source() | test.py:90:11:90:14 | After bm() | provenance | AdditionalTaintStep |
1717
nodes
18-
| test.py:21:11:21:18 | ControlFlowNode for source() | semmle.label | ControlFlowNode for source() |
19-
| test.py:22:10:22:24 | ControlFlowNode for Attribute() | semmle.label | ControlFlowNode for Attribute() |
20-
| test.py:29:11:29:18 | ControlFlowNode for source() | semmle.label | ControlFlowNode for source() |
21-
| test.py:32:5:32:7 | ControlFlowNode for val | semmle.label | ControlFlowNode for val |
22-
| test.py:33:10:33:12 | ControlFlowNode for val | semmle.label | ControlFlowNode for val |
23-
| test.py:40:5:40:7 | ControlFlowNode for val | semmle.label | ControlFlowNode for val |
24-
| test.py:40:11:40:25 | ControlFlowNode for Attribute() | semmle.label | ControlFlowNode for Attribute() |
25-
| test.py:41:10:41:12 | ControlFlowNode for val | semmle.label | ControlFlowNode for val |
26-
| test.py:45:11:45:18 | ControlFlowNode for source() | semmle.label | ControlFlowNode for source() |
27-
| test.py:53:5:53:7 | ControlFlowNode for val | semmle.label | ControlFlowNode for val |
28-
| test.py:53:11:53:25 | ControlFlowNode for Attribute() | semmle.label | ControlFlowNode for Attribute() |
29-
| test.py:54:10:54:12 | ControlFlowNode for val | semmle.label | ControlFlowNode for val |
30-
| test.py:70:11:70:18 | ControlFlowNode for source() | semmle.label | ControlFlowNode for source() |
31-
| test.py:78:5:78:7 | ControlFlowNode for val | semmle.label | ControlFlowNode for val |
32-
| test.py:78:11:78:14 | ControlFlowNode for bm() | semmle.label | ControlFlowNode for bm() |
33-
| test.py:79:10:79:12 | ControlFlowNode for val | semmle.label | ControlFlowNode for val |
34-
| test.py:83:11:83:18 | ControlFlowNode for source() | semmle.label | ControlFlowNode for source() |
35-
| test.py:90:5:90:7 | ControlFlowNode for val | semmle.label | ControlFlowNode for val |
36-
| test.py:90:11:90:14 | ControlFlowNode for bm() | semmle.label | ControlFlowNode for bm() |
37-
| test.py:91:10:91:12 | ControlFlowNode for val | semmle.label | ControlFlowNode for val |
38-
| test.py:107:11:107:18 | ControlFlowNode for source() | semmle.label | ControlFlowNode for source() |
18+
| test.py:21:11:21:18 | After source() | semmle.label | After source() |
19+
| test.py:22:10:22:24 | After Attribute() | semmle.label | After Attribute() |
20+
| test.py:29:11:29:18 | After source() | semmle.label | After source() |
21+
| test.py:32:5:32:7 | val | semmle.label | val |
22+
| test.py:33:10:33:12 | val | semmle.label | val |
23+
| test.py:40:5:40:7 | val | semmle.label | val |
24+
| test.py:40:11:40:25 | After Attribute() | semmle.label | After Attribute() |
25+
| test.py:41:10:41:12 | val | semmle.label | val |
26+
| test.py:45:11:45:18 | After source() | semmle.label | After source() |
27+
| test.py:53:5:53:7 | val | semmle.label | val |
28+
| test.py:53:11:53:25 | After Attribute() | semmle.label | After Attribute() |
29+
| test.py:54:10:54:12 | val | semmle.label | val |
30+
| test.py:70:11:70:18 | After source() | semmle.label | After source() |
31+
| test.py:78:5:78:7 | val | semmle.label | val |
32+
| test.py:78:11:78:14 | After bm() | semmle.label | After bm() |
33+
| test.py:79:10:79:12 | val | semmle.label | val |
34+
| test.py:83:11:83:18 | After source() | semmle.label | After source() |
35+
| test.py:90:5:90:7 | val | semmle.label | val |
36+
| test.py:90:11:90:14 | After bm() | semmle.label | After bm() |
37+
| test.py:91:10:91:12 | val | semmle.label | val |
38+
| test.py:107:11:107:18 | After source() | semmle.label | After source() |
3939
subpaths
4040
#select
41-
| test.py:22:10:22:24 | ControlFlowNode for Attribute() | test.py:21:11:21:18 | ControlFlowNode for source() | test.py:22:10:22:24 | ControlFlowNode for Attribute() | test flow (naive): test_simple |
42-
| test.py:33:10:33:12 | ControlFlowNode for val | test.py:29:11:29:18 | ControlFlowNode for source() | test.py:33:10:33:12 | ControlFlowNode for val | test flow (naive): test_alias |
43-
| test.py:41:10:41:12 | ControlFlowNode for val | test.py:45:11:45:18 | ControlFlowNode for source() | test.py:41:10:41:12 | ControlFlowNode for val | test flow (naive): test_across_functions |
44-
| test.py:54:10:54:12 | ControlFlowNode for val | test.py:70:11:70:18 | ControlFlowNode for source() | test.py:54:10:54:12 | ControlFlowNode for val | test flow (naive): test_deeply_nested |
45-
| test.py:79:10:79:12 | ControlFlowNode for val | test.py:83:11:83:18 | ControlFlowNode for source() | test.py:79:10:79:12 | ControlFlowNode for val | test flow (naive): test_pass_bound_method |
46-
| test.py:91:10:91:12 | ControlFlowNode for val | test.py:107:11:107:18 | ControlFlowNode for source() | test.py:91:10:91:12 | ControlFlowNode for val | test flow (naive): test_deeply_nested_bound_method |
41+
| test.py:22:10:22:24 | After Attribute() | test.py:21:11:21:18 | After source() | test.py:22:10:22:24 | After Attribute() | test flow (naive): test_simple |
42+
| test.py:33:10:33:12 | val | test.py:29:11:29:18 | After source() | test.py:33:10:33:12 | val | test flow (naive): test_alias |
43+
| test.py:41:10:41:12 | val | test.py:45:11:45:18 | After source() | test.py:41:10:41:12 | val | test flow (naive): test_across_functions |
44+
| test.py:54:10:54:12 | val | test.py:70:11:70:18 | After source() | test.py:54:10:54:12 | val | test flow (naive): test_deeply_nested |
45+
| test.py:79:10:79:12 | val | test.py:83:11:83:18 | After source() | test.py:79:10:79:12 | val | test flow (naive): test_pass_bound_method |
46+
| test.py:91:10:91:12 | val | test.py:107:11:107:18 | After source() | test.py:91:10:91:12 | val | test flow (naive): test_deeply_nested_bound_method |

python/ql/test/library-tests/frameworks/modeling-example/NaiveModel.ql

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44

55
private import python
6+
private import semmle.python.controlflow.internal.Cfg as Cfg
67
private import semmle.python.dataflow.new.DataFlow
78
private import semmle.python.dataflow.new.TaintTracking
89
import SharedFlow::PathGraph
@@ -13,7 +14,7 @@ class MyClassGetValueAdditionalTaintStep extends TaintTracking::AdditionalTaintS
1314
// obj -> obj.get_value()
1415
exists(DataFlow::Node bound_method |
1516
bound_method = myClassGetValue(nodeFrom) and
16-
nodeTo.asCfgNode().(CallNode).getFunction() = bound_method.asCfgNode()
17+
nodeTo.asCfgNode().(Cfg::CallNode).getFunction() = bound_method.asCfgNode()
1718
)
1819
}
1920
}

0 commit comments

Comments
 (0)