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

Skip to content

Commit 10bacfe

Browse files
committed
Python: Use subscriptUnknown instead of instance check.
Also adds a test for decomposing the unknown value of `a`.
1 parent 5bbf932 commit 10bacfe

11 files changed

Lines changed: 38 additions & 1 deletion

File tree

python/ql/src/semmle/python/pointsto/PointsTo.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -519,7 +519,7 @@ cached module PointsToInternal {
519519
sequence_index_points_to(rhs, context, sequence, value, index)
520520
or
521521
pointsTo(rhs, context, sequence, _) and
522-
sequence instanceof UnknownInstanceInternal and
522+
sequence.subscriptUnknown() and
523523
value = TUnknownInstance(ObjectInternal::builtin("object"))
524524
)
525525
}

python/ql/test/library-tests/PointsTo/new/Dataflow.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@
6464
| a_simple.py:49 | i_0 = c |
6565
| a_simple.py:53 | l_0 = BinaryExpr[0] |
6666
| a_simple.py:53 | m_0 = BinaryExpr[1] |
67+
| a_simple.py:56 | s_0 = a[0] |
68+
| a_simple.py:56 | u_0 = a[1] |
6769
| b_condition.py:0 | __name___0 = ScopeEntryDefinition |
6870
| b_condition.py:0 | __package___0 = ScopeEntryDefinition |
6971
| b_condition.py:0 | double_attr_check_0 = ScopeEntryDefinition |

python/ql/test/library-tests/PointsTo/new/Definitions.expected

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,8 @@
4747
| a_simple.py:49 | Local Variable i | AssignmentDefinition |
4848
| a_simple.py:53 | Local Variable l | MultiAssignmentDefinition |
4949
| a_simple.py:53 | Local Variable m | MultiAssignmentDefinition |
50+
| a_simple.py:56 | Local Variable s | MultiAssignmentDefinition |
51+
| a_simple.py:56 | Local Variable u | MultiAssignmentDefinition |
5052
| b_condition.py:0 | Global Variable __name__ | ScopeEntryDefinition |
5153
| b_condition.py:0 | Global Variable __package__ | ScopeEntryDefinition |
5254
| b_condition.py:0 | Global Variable double_attr_check | ScopeEntryDefinition |

python/ql/test/library-tests/PointsTo/new/PointsToUnknown.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
| a_simple.py:50 | ControlFlowNode for g | 38 |
1818
| a_simple.py:51 | ControlFlowNode for h | 38 |
1919
| a_simple.py:52 | ControlFlowNode for i | 38 |
20+
| a_simple.py:56 | ControlFlowNode for a | 38 |
2021
| b_condition.py:5 | ControlFlowNode for IfExp | 5 |
2122
| b_condition.py:5 | ControlFlowNode for cond | 5 |
2223
| b_condition.py:5 | ControlFlowNode for unknown | 5 |

python/ql/test/library-tests/PointsTo/new/PointsToWithContext.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ WARNING: Predicate points_to has been deprecated and may be removed in future (P
2222
| a_simple.py:18 | ControlFlowNode for multi_loop | Function multi_loop | builtin-class function | 18 | import |
2323
| a_simple.py:19 | ControlFlowNode for None | NoneType None | builtin-class NoneType | 19 | runtime |
2424
| a_simple.py:19 | ControlFlowNode for x | NoneType None | builtin-class NoneType | 19 | runtime |
25+
| a_simple.py:21 | ControlFlowNode for x | x | builtin-class object | 20 | runtime |
2526
| a_simple.py:23 | ControlFlowNode for FunctionExpr | Function with_definition | builtin-class function | 23 | import |
2627
| a_simple.py:23 | ControlFlowNode for with_definition | Function with_definition | builtin-class function | 23 | import |
2728
| a_simple.py:27 | ControlFlowNode for FunctionExpr | Function multi_loop_in_try | builtin-class function | 27 | import |
2829
| a_simple.py:27 | ControlFlowNode for multi_loop_in_try | Function multi_loop_in_try | builtin-class function | 27 | import |
30+
| a_simple.py:30 | ControlFlowNode for p | p | builtin-class object | 29 | runtime |
2931
| a_simple.py:31 | ControlFlowNode for KeyError | builtin-class KeyError | builtin-class type | 31 | runtime |
3032
| a_simple.py:34 | ControlFlowNode for FunctionExpr | Function f | builtin-class function | 34 | import |
3133
| a_simple.py:34 | ControlFlowNode for args | args | builtin-class tuple | 34 | runtime |
@@ -75,6 +77,8 @@ WARNING: Predicate points_to has been deprecated and may be removed in future (P
7577
| a_simple.py:53 | ControlFlowNode for Tuple | Tuple | builtin-class tuple | 53 | runtime |
7678
| a_simple.py:54 | ControlFlowNode for l | l | builtin-class object | 53 | runtime |
7779
| a_simple.py:55 | ControlFlowNode for m | m | builtin-class object | 53 | runtime |
80+
| a_simple.py:57 | ControlFlowNode for s | s | builtin-class object | 56 | runtime |
81+
| a_simple.py:58 | ControlFlowNode for u | u | builtin-class object | 56 | runtime |
7882
| b_condition.py:4 | ControlFlowNode for FunctionExpr | Function f | builtin-class function | 4 | import |
7983
| b_condition.py:4 | ControlFlowNode for f | Function f | builtin-class function | 4 | import |
8084
| b_condition.py:5 | ControlFlowNode for IfExp | NoneType None | builtin-class NoneType | 5 | runtime |
@@ -1080,6 +1084,7 @@ WARNING: Predicate points_to has been deprecated and may be removed in future (P
10801084
| r_regressions.py:42 | ControlFlowNode for FunctionExpr | Function find_library | builtin-class function | 42 | import |
10811085
| r_regressions.py:42 | ControlFlowNode for find_library | Function find_library | builtin-class function | 42 | import |
10821086
| r_regressions.py:43 | ControlFlowNode for List | List | builtin-class list | 43 | runtime |
1087+
| r_regressions.py:44 | ControlFlowNode for data | data | builtin-class object | 43 | runtime |
10831088
| r_regressions.py:46 | ControlFlowNode for FunctionExpr | Function fail | builtin-class function | 46 | import |
10841089
| r_regressions.py:46 | ControlFlowNode for fail | Function fail | builtin-class function | 46 | import |
10851090
| r_regressions.py:49 | ControlFlowNode for C | class C | builtin-class type | 49 | import |

python/ql/test/library-tests/PointsTo/new/PointsToWithType.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,10 +22,12 @@ WARNING: Predicate points_to has been deprecated and may be removed in future (P
2222
| a_simple.py:18 | ControlFlowNode for multi_loop | Function multi_loop | builtin-class function | 18 |
2323
| a_simple.py:19 | ControlFlowNode for None | NoneType None | builtin-class NoneType | 19 |
2424
| a_simple.py:19 | ControlFlowNode for x | NoneType None | builtin-class NoneType | 19 |
25+
| a_simple.py:21 | ControlFlowNode for x | x | builtin-class object | 20 |
2526
| a_simple.py:23 | ControlFlowNode for FunctionExpr | Function with_definition | builtin-class function | 23 |
2627
| a_simple.py:23 | ControlFlowNode for with_definition | Function with_definition | builtin-class function | 23 |
2728
| a_simple.py:27 | ControlFlowNode for FunctionExpr | Function multi_loop_in_try | builtin-class function | 27 |
2829
| a_simple.py:27 | ControlFlowNode for multi_loop_in_try | Function multi_loop_in_try | builtin-class function | 27 |
30+
| a_simple.py:30 | ControlFlowNode for p | p | builtin-class object | 29 |
2931
| a_simple.py:31 | ControlFlowNode for KeyError | builtin-class KeyError | builtin-class type | 31 |
3032
| a_simple.py:34 | ControlFlowNode for FunctionExpr | Function f | builtin-class function | 34 |
3133
| a_simple.py:34 | ControlFlowNode for args | args | builtin-class tuple | 34 |
@@ -75,6 +77,8 @@ WARNING: Predicate points_to has been deprecated and may be removed in future (P
7577
| a_simple.py:53 | ControlFlowNode for Tuple | Tuple | builtin-class tuple | 53 |
7678
| a_simple.py:54 | ControlFlowNode for l | l | builtin-class object | 53 |
7779
| a_simple.py:55 | ControlFlowNode for m | m | builtin-class object | 53 |
80+
| a_simple.py:57 | ControlFlowNode for s | s | builtin-class object | 56 |
81+
| a_simple.py:58 | ControlFlowNode for u | u | builtin-class object | 56 |
7882
| b_condition.py:4 | ControlFlowNode for FunctionExpr | Function f | builtin-class function | 4 |
7983
| b_condition.py:4 | ControlFlowNode for f | Function f | builtin-class function | 4 |
8084
| b_condition.py:5 | ControlFlowNode for IfExp | NoneType None | builtin-class NoneType | 5 |

python/ql/test/library-tests/PointsTo/new/SourceNodeDefinitions.expected

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,9 @@
5151
| a_simple.py:38 | Local Variable p | Entry node for Function multi_assign_and_packing | definition |
5252
| a_simple.py:38 | Local Variable q | Entry node for Function multi_assign_and_packing | definition |
5353
| a_simple.py:38 | Local Variable r | Entry node for Function multi_assign_and_packing | definition |
54+
| a_simple.py:38 | Local Variable s | Entry node for Function multi_assign_and_packing | definition |
5455
| a_simple.py:38 | Local Variable t | Entry node for Function multi_assign_and_packing | definition |
56+
| a_simple.py:38 | Local Variable u | Entry node for Function multi_assign_and_packing | definition |
5557
| a_simple.py:38 | Local Variable w | Entry node for Function multi_assign_and_packing | definition |
5658
| a_simple.py:38 | Local Variable x | Entry node for Function multi_assign_and_packing | definition |
5759
| a_simple.py:38 | Local Variable y | Entry node for Function multi_assign_and_packing | definition |
@@ -69,6 +71,8 @@
6971
| a_simple.py:49 | Local Variable i | ControlFlowNode for i | definition |
7072
| a_simple.py:53 | Local Variable l | ControlFlowNode for l | definition |
7173
| a_simple.py:53 | Local Variable m | ControlFlowNode for m | definition |
74+
| a_simple.py:56 | Local Variable s | ControlFlowNode for s | definition |
75+
| a_simple.py:56 | Local Variable u | ControlFlowNode for u | definition |
7276
| b_condition.py:0 | Global Variable __name__ | Entry node for Module code.b_condition | definition |
7377
| b_condition.py:0 | Global Variable __package__ | Entry node for Module code.b_condition | definition |
7478
| b_condition.py:0 | Global Variable double_attr_check | Entry node for Module code.b_condition | definition |

python/ql/test/library-tests/PointsTo/new/SsaUses.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@
6767
| a_simple.py:38 | p_0 | Exit node for Function multi_assign_and_packing |
6868
| a_simple.py:38 | q_0 | Exit node for Function multi_assign_and_packing |
6969
| a_simple.py:38 | r_0 | Exit node for Function multi_assign_and_packing |
70+
| a_simple.py:38 | s_0 | Exit node for Function multi_assign_and_packing |
7071
| a_simple.py:38 | t_0 | Exit node for Function multi_assign_and_packing |
72+
| a_simple.py:38 | u_0 | Exit node for Function multi_assign_and_packing |
7173
| a_simple.py:38 | w_0 | Exit node for Function multi_assign_and_packing |
7274
| a_simple.py:38 | x_0 | Exit node for Function multi_assign_and_packing |
7375
| a_simple.py:38 | y_0 | Exit node for Function multi_assign_and_packing |
@@ -91,6 +93,9 @@
9193
| a_simple.py:52 | i_0 | ControlFlowNode for i |
9294
| a_simple.py:54 | l_0 | ControlFlowNode for l |
9395
| a_simple.py:55 | m_0 | ControlFlowNode for m |
96+
| a_simple.py:56 | a_0 | ControlFlowNode for a |
97+
| a_simple.py:57 | s_0 | ControlFlowNode for s |
98+
| a_simple.py:58 | u_0 | ControlFlowNode for u |
9499
| b_condition.py:0 | __name___0 | Exit node for Module code.b_condition |
95100
| b_condition.py:0 | __package___0 | Exit node for Module code.b_condition |
96101
| b_condition.py:0 | double_attr_check_1 | Exit node for Module code.b_condition |

python/ql/test/library-tests/PointsTo/new/Values.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111
| a_simple.py:16 | ControlFlowNode for d | runtime | instance of dict | builtin-class dict |
1212
| a_simple.py:18 | ControlFlowNode for FunctionExpr | import | Function multi_loop | builtin-class function |
1313
| a_simple.py:19 | ControlFlowNode for None | runtime | None | builtin-class NoneType |
14+
| a_simple.py:21 | ControlFlowNode for x | runtime | instance of object | builtin-class object |
1415
| a_simple.py:23 | ControlFlowNode for FunctionExpr | import | Function with_definition | builtin-class function |
1516
| a_simple.py:27 | ControlFlowNode for FunctionExpr | import | Function multi_loop_in_try | builtin-class function |
17+
| a_simple.py:30 | ControlFlowNode for p | runtime | instance of object | builtin-class object |
1618
| a_simple.py:31 | ControlFlowNode for KeyError | runtime | builtin-class KeyError | builtin-class type |
1719
| a_simple.py:34 | ControlFlowNode for FunctionExpr | import | Function f | builtin-class function |
1820
| a_simple.py:35 | ControlFlowNode for IntegerLiteral | runtime | int 0 | builtin-class int |
@@ -61,6 +63,8 @@
6163
| a_simple.py:53 | ControlFlowNode for Tuple | runtime | (int 2, ) | builtin-class tuple |
6264
| a_simple.py:54 | ControlFlowNode for l | runtime | instance of object | builtin-class object |
6365
| a_simple.py:55 | ControlFlowNode for m | runtime | instance of object | builtin-class object |
66+
| a_simple.py:57 | ControlFlowNode for s | runtime | instance of object | builtin-class object |
67+
| a_simple.py:58 | ControlFlowNode for u | runtime | instance of object | builtin-class object |
6468
| b_condition.py:4 | ControlFlowNode for FunctionExpr | import | Function f | builtin-class function |
6569
| b_condition.py:5 | ControlFlowNode for IfExp | runtime | None | builtin-class NoneType |
6670
| b_condition.py:5 | ControlFlowNode for None | runtime | None | builtin-class NoneType |
@@ -866,6 +870,7 @@
866870
| r_regressions.py:36 | ControlFlowNode for z | runtime | int 0 | builtin-class int |
867871
| r_regressions.py:42 | ControlFlowNode for FunctionExpr | import | Function find_library | builtin-class function |
868872
| r_regressions.py:43 | ControlFlowNode for List | runtime | List | builtin-class list |
873+
| r_regressions.py:44 | ControlFlowNode for data | runtime | instance of object | builtin-class object |
869874
| r_regressions.py:46 | ControlFlowNode for FunctionExpr | import | Function fail | builtin-class function |
870875
| r_regressions.py:49 | ControlFlowNode for ClassExpr | import | class C | builtin-class type |
871876
| r_regressions.py:49 | ControlFlowNode for object | import | builtin-class object | builtin-class type |

python/ql/test/library-tests/PointsTo/new/VarUses.expected

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,9 @@
5252
| a_simple.py:38 | p | Exit node for Function multi_assign_and_packing |
5353
| a_simple.py:38 | q | Exit node for Function multi_assign_and_packing |
5454
| a_simple.py:38 | r | Exit node for Function multi_assign_and_packing |
55+
| a_simple.py:38 | s | Exit node for Function multi_assign_and_packing |
5556
| a_simple.py:38 | t | Exit node for Function multi_assign_and_packing |
57+
| a_simple.py:38 | u | Exit node for Function multi_assign_and_packing |
5658
| a_simple.py:38 | w | Exit node for Function multi_assign_and_packing |
5759
| a_simple.py:38 | x | Exit node for Function multi_assign_and_packing |
5860
| a_simple.py:38 | y | Exit node for Function multi_assign_and_packing |
@@ -76,6 +78,9 @@
7678
| a_simple.py:52 | i | ControlFlowNode for i |
7779
| a_simple.py:54 | l | ControlFlowNode for l |
7880
| a_simple.py:55 | m | ControlFlowNode for m |
81+
| a_simple.py:56 | a | ControlFlowNode for a |
82+
| a_simple.py:57 | s | ControlFlowNode for s |
83+
| a_simple.py:58 | u | ControlFlowNode for u |
7984
| b_condition.py:0 | Exception | Exit node for Module code.b_condition |
8085
| b_condition.py:0 | TypeError | Exit node for Module code.b_condition |
8186
| b_condition.py:0 | __name__ | Exit node for Module code.b_condition |

0 commit comments

Comments
 (0)