Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a73473

Browse files
committed
Python: Control flow nodes are dataflow nodes
iff they are expression nodes We could refine this later, but it seems to work for now...
1 parent 18e946d commit 5a73473

9 files changed

Lines changed: 53 additions & 17 deletions

File tree

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

Lines changed: 4 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,11 @@ private import DataFlowPublic
77
//--------
88
// Nodes
99
//--------
10-
/** A control flow node which is also a dataflow node */
11-
abstract class DataFlowCfgNode extends ControlFlowNode { }
12-
13-
/** Literals contribute to dataflow */
14-
class CfgLiteralNode extends DataFlowCfgNode {
15-
CfgLiteralNode() { this.isLiteral() }
16-
}
10+
predicate isExpressionNode(ControlFlowNode node) { node.getNode() instanceof Expr }
1711

18-
/** Variables contribute to dataflow */
19-
class CfgNameNode extends DataFlowCfgNode {
20-
CfgNameNode() { this instanceof NameNode }
21-
}
22-
23-
/** Calls contribute to dataflow */
24-
class CfgCallNode extends DataFlowCfgNode {
25-
CfgCallNode() { this instanceof CallNode }
12+
/** A control flow node which is also a dataflow node */
13+
class DataFlowCfgNode extends ControlFlowNode {
14+
DataFlowCfgNode() { isExpressionNode(this) }
2615
}
2716

2817
/**

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,12 @@ class CfgNode extends Node, TCfgNode {
9090
* to multiple `ExprNode`s, just like it may correspond to multiple
9191
* `ControlFlow::Node`s.
9292
*/
93-
class ExprNode extends CfgNode { }
93+
class ExprNode extends CfgNode {
94+
ExprNode() { isExpressionNode(node) }
95+
}
9496

9597
/** Gets a node corresponding to expression `e`. */
96-
ExprNode exprNode(DataFlowExpr e) { none() }
98+
ExprNode exprNode(DataFlowExpr e) { result.getNode().getNode() = e }
9799

98100
/**
99101
* The value of a parameter at function entry, viewed as a node in a data

python/ql/test/experimental/dataflow/basic/global.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,10 @@
44
| test.py:0:0:0:0 | GSSA Variable __package__ | test.py:7:5:7:20 | ControlFlowNode for obfuscated_id() |
55
| test.py:0:0:0:0 | GSSA Variable b | test.py:7:1:7:1 | GSSA Variable b |
66
| test.py:0:0:0:0 | GSSA Variable b | test.py:7:5:7:20 | ControlFlowNode for obfuscated_id() |
7+
| test.py:1:1:1:21 | ControlFlowNode for FunctionExpr | test.py:1:5:1:17 | GSSA Variable obfuscated_id |
8+
| test.py:1:1:1:21 | ControlFlowNode for FunctionExpr | test.py:7:1:7:1 | GSSA Variable b |
9+
| test.py:1:1:1:21 | ControlFlowNode for FunctionExpr | test.py:7:5:7:17 | ControlFlowNode for obfuscated_id |
10+
| test.py:1:1:1:21 | ControlFlowNode for FunctionExpr | test.py:7:5:7:20 | ControlFlowNode for obfuscated_id() |
711
| test.py:1:5:1:17 | GSSA Variable obfuscated_id | test.py:7:1:7:1 | GSSA Variable b |
812
| test.py:1:5:1:17 | GSSA Variable obfuscated_id | test.py:7:5:7:17 | ControlFlowNode for obfuscated_id |
913
| test.py:1:5:1:17 | GSSA Variable obfuscated_id | test.py:7:5:7:20 | ControlFlowNode for obfuscated_id() |

python/ql/test/experimental/dataflow/basic/globalStep.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
| test.py:0:0:0:0 | GSSA Variable __package__ | test.py:7:5:7:20 | ControlFlowNode for obfuscated_id() |
55
| test.py:0:0:0:0 | GSSA Variable b | test.py:7:5:7:20 | ControlFlowNode for obfuscated_id() |
66
| test.py:0:0:0:0 | GSSA Variable b | test.py:7:5:7:20 | ControlFlowNode for obfuscated_id() |
7+
| test.py:1:1:1:21 | ControlFlowNode for FunctionExpr | test.py:1:5:1:17 | GSSA Variable obfuscated_id |
8+
| test.py:1:1:1:21 | ControlFlowNode for FunctionExpr | test.py:1:5:1:17 | GSSA Variable obfuscated_id |
79
| test.py:1:5:1:17 | GSSA Variable obfuscated_id | test.py:7:5:7:17 | ControlFlowNode for obfuscated_id |
810
| test.py:1:5:1:17 | GSSA Variable obfuscated_id | test.py:7:5:7:17 | ControlFlowNode for obfuscated_id |
911
| test.py:1:5:1:17 | GSSA Variable obfuscated_id | test.py:7:5:7:20 | ControlFlowNode for obfuscated_id() |

python/ql/test/experimental/dataflow/basic/local.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
| test.py:0:0:0:0 | GSSA Variable __package__ | test.py:0:0:0:0 | GSSA Variable __package__ |
33
| test.py:0:0:0:0 | GSSA Variable b | test.py:0:0:0:0 | GSSA Variable b |
44
| test.py:0:0:0:0 | SSA variable $ | test.py:0:0:0:0 | SSA variable $ |
5+
| test.py:1:1:1:21 | ControlFlowNode for FunctionExpr | test.py:1:1:1:21 | ControlFlowNode for FunctionExpr |
56
| test.py:1:5:1:17 | ControlFlowNode for obfuscated_id | test.py:1:5:1:17 | ControlFlowNode for obfuscated_id |
67
| test.py:1:5:1:17 | GSSA Variable obfuscated_id | test.py:1:5:1:17 | GSSA Variable obfuscated_id |
78
| test.py:1:19:1:19 | ControlFlowNode for x | test.py:1:19:1:19 | ControlFlowNode for x |

python/ql/test/experimental/dataflow/basic/sinks.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
| test.py:0:0:0:0 | GSSA Variable __package__ |
33
| test.py:0:0:0:0 | GSSA Variable b |
44
| test.py:0:0:0:0 | SSA variable $ |
5+
| test.py:1:1:1:21 | ControlFlowNode for FunctionExpr |
56
| test.py:1:5:1:17 | ControlFlowNode for obfuscated_id |
67
| test.py:1:5:1:17 | GSSA Variable obfuscated_id |
78
| test.py:1:19:1:19 | ControlFlowNode for x |

python/ql/test/experimental/dataflow/basic/sources.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
| test.py:0:0:0:0 | GSSA Variable __package__ |
33
| test.py:0:0:0:0 | GSSA Variable b |
44
| test.py:0:0:0:0 | SSA variable $ |
5+
| test.py:1:1:1:21 | ControlFlowNode for FunctionExpr |
56
| test.py:1:5:1:17 | ControlFlowNode for obfuscated_id |
67
| test.py:1:5:1:17 | GSSA Variable obfuscated_id |
78
| test.py:1:19:1:19 | ControlFlowNode for x |

python/ql/test/experimental/dataflow/consistency/dataflow-consistency.expected

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,71 @@ uniqueEnclosingCallable
55
| test.py:0:0:0:0 | GSSA Variable test24 | Node should have one enclosing callable but has 0. |
66
| test.py:0:0:0:0 | GSSA Variable test_truth | Node should have one enclosing callable but has 0. |
77
| test.py:0:0:0:0 | GSSA Variable test_update_extend | Node should have one enclosing callable but has 0. |
8+
| test.py:6:1:6:12 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
89
| test.py:6:5:6:9 | GSSA Variable test1 | Node should have one enclosing callable but has 0. |
10+
| test.py:9:1:9:12 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
911
| test.py:9:5:9:9 | GSSA Variable test2 | Node should have one enclosing callable but has 0. |
12+
| test.py:13:1:13:13 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
1013
| test.py:13:5:13:10 | GSSA Variable source | Node should have one enclosing callable but has 0. |
14+
| test.py:16:1:16:14 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
1115
| test.py:16:5:16:8 | GSSA Variable sink | Node should have one enclosing callable but has 0. |
16+
| test.py:19:1:19:12 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
1217
| test.py:19:5:19:9 | GSSA Variable test3 | Node should have one enclosing callable but has 0. |
18+
| test.py:23:1:23:12 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
1319
| test.py:23:5:23:9 | GSSA Variable test4 | Node should have one enclosing callable but has 0. |
20+
| test.py:27:1:27:12 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
1421
| test.py:27:5:27:9 | GSSA Variable test5 | Node should have one enclosing callable but has 0. |
22+
| test.py:31:1:31:16 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
1523
| test.py:31:5:31:9 | GSSA Variable test6 | Node should have one enclosing callable but has 0. |
24+
| test.py:39:1:39:16 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
1625
| test.py:39:5:39:9 | GSSA Variable test7 | Node should have one enclosing callable but has 0. |
26+
| test.py:47:1:47:17 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
1727
| test.py:47:5:47:11 | GSSA Variable source2 | Node should have one enclosing callable but has 0. |
28+
| test.py:50:1:50:15 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
1829
| test.py:50:5:50:9 | GSSA Variable sink2 | Node should have one enclosing callable but has 0. |
30+
| test.py:53:1:53:21 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
1931
| test.py:53:5:53:9 | GSSA Variable sink3 | Node should have one enclosing callable but has 0. |
32+
| test.py:57:1:57:16 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
2033
| test.py:57:5:57:9 | GSSA Variable test8 | Node should have one enclosing callable but has 0. |
34+
| test.py:62:1:62:16 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
2135
| test.py:62:5:62:9 | GSSA Variable test9 | Node should have one enclosing callable but has 0. |
36+
| test.py:69:1:69:17 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
2237
| test.py:69:5:69:10 | GSSA Variable test10 | Node should have one enclosing callable but has 0. |
38+
| test.py:76:1:76:13 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
2339
| test.py:76:5:76:7 | GSSA Variable hub | Node should have one enclosing callable but has 0. |
40+
| test.py:79:1:79:13 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
2441
| test.py:79:5:79:10 | GSSA Variable test11 | Node should have one enclosing callable but has 0. |
42+
| test.py:84:1:84:13 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
2543
| test.py:84:5:84:10 | GSSA Variable test12 | Node should have one enclosing callable but has 0. |
44+
| test.py:89:8:89:13 | ControlFlowNode for ImportExpr | Node should have one enclosing callable but has 0. |
2645
| test.py:89:8:89:13 | GSSA Variable module | Node should have one enclosing callable but has 0. |
46+
| test.py:91:1:91:13 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
2747
| test.py:91:5:91:10 | GSSA Variable test13 | Node should have one enclosing callable but has 0. |
48+
| test.py:95:1:95:13 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
2849
| test.py:95:5:95:10 | GSSA Variable test14 | Node should have one enclosing callable but has 0. |
50+
| test.py:99:1:99:13 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
2951
| test.py:99:5:99:10 | GSSA Variable test15 | Node should have one enclosing callable but has 0. |
52+
| test.py:103:1:103:13 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
3053
| test.py:103:5:103:10 | GSSA Variable test16 | Node should have one enclosing callable but has 0. |
54+
| test.py:108:1:108:17 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
3155
| test.py:108:5:108:10 | GSSA Variable test20 | Node should have one enclosing callable but has 0. |
56+
| test.py:118:1:118:17 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
3257
| test.py:118:5:118:10 | GSSA Variable test21 | Node should have one enclosing callable but has 0. |
58+
| test.py:128:1:128:17 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
3359
| test.py:128:5:128:10 | GSSA Variable test22 | Node should have one enclosing callable but has 0. |
60+
| test.py:139:20:139:38 | ControlFlowNode for ImportMember | Node should have one enclosing callable but has 0. |
3461
| test.py:139:33:139:38 | GSSA Variable unsafe | Node should have one enclosing callable but has 0. |
3562
| test.py:140:1:140:12 | ControlFlowNode for SINK() | Node should have one enclosing callable but has 0. |
3663
| test.py:140:1:140:12 | GSSA Variable unsafe | Node should have one enclosing callable but has 0. |
3764
| test.py:140:6:140:11 | ControlFlowNode for unsafe | Node should have one enclosing callable but has 0. |
65+
| test.py:142:1:142:13 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
66+
| test.py:142:5:142:10 | GSSA Variable test23 | Node should have one enclosing callable but has 0. |
67+
| test.py:146:1:146:13 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
68+
| test.py:146:5:146:10 | GSSA Variable test24 | Node should have one enclosing callable but has 0. |
69+
| test.py:151:1:151:29 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
70+
| test.py:151:5:151:22 | GSSA Variable test_update_extend | Node should have one enclosing callable but has 0. |
71+
| test.py:161:1:161:17 | ControlFlowNode for FunctionExpr | Node should have one enclosing callable but has 0. |
72+
| test.py:161:5:161:14 | GSSA Variable test_truth | Node should have one enclosing callable but has 0. |
3873
uniqueType
3974
uniqueNodeLocation
4075
missingLocation

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
| test.py:32:10:32:26 | ControlFlowNode for Tuple | test.py:32:5:32:5 | SSA variable x |
33
| test.py:33:5:33:5 | SSA variable y | test.py:34:5:34:11 | SSA variable y |
44
| test.py:33:5:33:5 | SSA variable y | test.py:34:10:34:10 | ControlFlowNode for y |
5+
| test.py:33:9:33:12 | ControlFlowNode for Subscript | test.py:33:5:33:5 | SSA variable y |

0 commit comments

Comments
 (0)