Skip to content

Commit ef0ea24

Browse files
authored
Merge pull request github#5679 from tausbn/python-fix-bad-points-to-joins
Python: Fix bad points-to joins
2 parents 3eba5b0 + 897d124 commit ef0ea24

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

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

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1853,8 +1853,10 @@ module Expressions {
18531853
private boolean isinstanceEvaluatesTo(
18541854
CallNode call, PointsToContext context, ControlFlowNode use, ObjectInternal val
18551855
) {
1856-
exists(ObjectInternal cls | isinstance_call(call, use, context, val, cls) |
1857-
result = Types::improperSubclass(val.getClass(), cls)
1856+
exists(ObjectInternal cls, ObjectInternal val_cls |
1857+
isinstance_call(call, use, context, val, val_cls, cls)
1858+
|
1859+
result = Types::improperSubclass(val_cls, cls)
18581860
or
18591861
val = ObjectInternal::unknown() and result = maybe()
18601862
or
@@ -1866,12 +1868,13 @@ module Expressions {
18661868

18671869
private predicate isinstance_call(
18681870
CallNode call, ControlFlowNode use, PointsToContext context, ObjectInternal val,
1869-
ObjectInternal cls
1871+
ObjectInternal val_cls, ObjectInternal cls
18701872
) {
18711873
exists(ControlFlowNode func, ControlFlowNode arg1 |
18721874
call2(call, func, use, arg1) and
18731875
points_to_isinstance(func, context) and
18741876
PointsToInternal::pointsTo(use, context, val, _) and
1877+
val_cls = val.getClass() and
18751878
PointsToInternal::pointsTo(arg1, context, cls, _)
18761879
)
18771880
}
@@ -1993,10 +1996,7 @@ module Expressions {
19931996
exists(ObjectInternal sup_or_tuple |
19941997
issubclass_call(_, _, _, sub, sup_or_tuple) and sub.isClass() = true
19951998
or
1996-
exists(ObjectInternal val |
1997-
isinstance_call(_, _, _, val, sup_or_tuple) and
1998-
sub = val.getClass()
1999-
)
1999+
exists(ObjectInternal val | isinstance_call(_, _, _, val, sub, sup_or_tuple))
20002000
|
20012001
sup = sup_or_tuple
20022002
or

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,14 @@ private int total_call_cost(CallNode call) {
100100
if call_to_init_or_del(call) then result = 1 else result = call_cost(call) + splay_cost(call)
101101
}
102102

103+
pragma[nomagic]
104+
private int relevant_call_cost(PointsToContext ctx, CallNode call) {
105+
ctx.appliesTo(call) and result = total_call_cost(call)
106+
}
107+
103108
pragma[noinline]
104109
private int total_cost(CallNode call, PointsToContext ctx) {
105-
ctx.appliesTo(call) and
106-
result = total_call_cost(call) + context_cost(ctx)
110+
result = relevant_call_cost(ctx, call) + context_cost(ctx)
107111
}
108112

109113
cached

0 commit comments

Comments
 (0)