Skip to content

Commit 32cc7c7

Browse files
authored
Merge pull request #858 from markshannon/python-a-few-more-unknowns
Python: Slight improvement to reachability in points-to
2 parents 6243c72 + 24d678b commit 32cc7c7

File tree

7 files changed

+22
-5
lines changed

7 files changed

+22
-5
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -610,7 +610,6 @@ module PointsTo {
610610
points_to(obj_node, context, x, icls, _) and
611611
(not x instanceof ModuleObject and not x instanceof ClassObject) and
612612
not icls.isBuiltin() and
613-
Types::class_has_attribute_bool(icls, name) = false and
614613
value = unknownValue() and cls = theUnknownType() and origin = f
615614
)
616615
)
@@ -2117,10 +2116,15 @@ module PointsTo {
21172116
private boolean truth_test_evaluates_boolean(ControlFlowNode expr, ControlFlowNode use, PointsToContext context, Object val, ClassObject cls, ControlFlowNode origin) {
21182117
contains_interesting_expression_within_test(expr, use) and
21192118
points_to(use, context, val, cls, origin) and
2119+
expr = use and
21202120
(
2121-
expr = use and val.booleanValue() = result
2121+
val.booleanValue() = result
21222122
or
2123-
expr = use and Types::instances_always_true(cls) and result = true
2123+
Types::instances_always_true(cls) and result = true
2124+
or
2125+
val.maybe() and result = true
2126+
or
2127+
val.maybe() and result = false
21242128
)
21252129
}
21262130

python/ql/test/library-tests/PointsTo/guarded/PointsTo.expected

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
| test.py | 408 | ControlFlowNode for x | int 1 | 404 |
6262
| test.py | 420 | ControlFlowNode for Attribute | NoneType None | 418 |
6363
| test.py | 427 | ControlFlowNode for Attribute | NoneType None | 418 |
64+
| test.py | 435 | ControlFlowNode for y | int 1 | 433 |
6465
| type_test.py | 5 | ControlFlowNode for d | Dict | 2 |
6566
| type_test.py | 14 | ControlFlowNode for x | int 0 | 11 |
6667
| type_test.py | 16 | ControlFlowNode for x | float 1.0 | 11 |

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
| test.py | 408 | ControlFlowNode for x | int 1 | builtin-class int | 404 |
6262
| test.py | 420 | ControlFlowNode for Attribute | NoneType None | builtin-class NoneType | 418 |
6363
| test.py | 427 | ControlFlowNode for Attribute | NoneType None | builtin-class NoneType | 418 |
64+
| test.py | 435 | ControlFlowNode for y | int 1 | builtin-class int | 433 |
6465
| type_test.py | 5 | ControlFlowNode for d | Dict | builtin-class dict | 2 |
6566
| type_test.py | 14 | ControlFlowNode for x | int 0 | builtin-class int | 11 |
6667
| type_test.py | 16 | ControlFlowNode for x | float 1.0 | builtin-class float | 11 |

python/ql/test/library-tests/PointsTo/guarded/test.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,3 +426,10 @@ def meth(self):
426426
else:
427427
use(self.x)
428428
return lambda : use(self.x)
429+
430+
431+
def test_on_unknown_attr():
432+
e = E()
433+
y = 1
434+
if e.attr:
435+
use(y)

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@
106106
| b_condition.py:88 | ControlFlowNode for y | 87 |
107107
| b_condition.py:90 | ControlFlowNode for x | 87 |
108108
| b_condition.py:90 | ControlFlowNode for y | 87 |
109+
| b_condition.py:92 | ControlFlowNode for x | 87 |
109110
| b_condition.py:93 | ControlFlowNode for use | 93 |
110111
| b_condition.py:93 | ControlFlowNode for use() | 93 |
111112
| b_condition.py:93 | ControlFlowNode for y | 87 |
@@ -115,6 +116,7 @@
115116
| b_condition.py:96 | ControlFlowNode for y | 87 |
116117
| b_condition.py:97 | ControlFlowNode for use | 97 |
117118
| b_condition.py:97 | ControlFlowNode for use() | 97 |
119+
| b_condition.py:97 | ControlFlowNode for x | 87 |
118120
| b_condition.py:99 | ControlFlowNode for use | 99 |
119121
| b_condition.py:99 | ControlFlowNode for use() | 99 |
120122
| b_condition.py:102 | ControlFlowNode for a | 101 |
@@ -225,3 +227,5 @@
225227
| r_regressions.py:52 | ControlFlowNode for msg | 51 |
226228
| r_regressions.py:64 | ControlFlowNode for do_validation | 64 |
227229
| r_regressions.py:64 | ControlFlowNode for do_validation() | 64 |
230+
| r_regressions.py:90 | ControlFlowNode for Attribute | 90 |
231+
| r_regressions.py:90 | ControlFlowNode for Attribute() | 90 |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| 0 | 29 | 29 | 100.0 |
1+
| 0 | 31 | 31 | 100.0 |
22
| 1 | 4 | 40 | 10.0 |
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
1-
| 0 | 29 | 29 | 100.0 |
1+
| 0 | 31 | 31 | 100.0 |
22
| 1 | 3 | 40 | 7.5 |

0 commit comments

Comments
 (0)