Skip to content

Commit 897d124

Browse files
authored
Python: Prevent bad join in isinstanceEvaluatesTo
In some cases, we were joining the result of `val.getClass()` against the first argument of `Types::improperSubclass` before filtering out the vast majority of tuples by the call to `isinstance_call`. To fix this, we let `isinstance_call` take care of figuring out the class of the value being tested. As a bonus, this cleans up the only other place where `isinstance_call` is used, where we _also_ want to know the class of the value being tested in the `isinstance` call.
1 parent a7fcf52 commit 897d124

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
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

0 commit comments

Comments
 (0)