Skip to content

Commit d9b337c

Browse files
authored
Merge pull request #16804 from github/tausbn/python-fix-bad-join-in-dataflow-dispatch
Python: Fix bad join in `DataFlowDispatch`
2 parents c6d02e4 + 6db7e72 commit d9b337c

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowDispatch.qll

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -829,10 +829,16 @@ Function findFunctionAccordingToMro(Class cls, string name) {
829829
result = cls.getAMethod() and
830830
result.getName() = name
831831
or
832-
not cls.getAMethod().getName() = name and
832+
not class_has_method(cls, name) and
833833
result = findFunctionAccordingToMro(getNextClassInMro(cls), name)
834834
}
835835

836+
/**
837+
* Join-order helper for `findFunctionAccordingToMro` and `findFunctionAccordingToMroKnownStartingClass`.
838+
*/
839+
pragma[nomagic]
840+
private predicate class_has_method(Class cls, string name) { cls.getAMethod().getName() = name }
841+
836842
/**
837843
* Gets a class that, from an approximated MRO calculation, might be the next class
838844
* after `cls` in the MRO for `startingClass`.
@@ -860,7 +866,7 @@ private Function findFunctionAccordingToMroKnownStartingClass(
860866
result.getName() = name and
861867
cls = getADirectSuperclass*(startingClass)
862868
or
863-
not cls.getAMethod().getName() = name and
869+
not class_has_method(cls, name) and
864870
result =
865871
findFunctionAccordingToMroKnownStartingClass(getNextClassInMroKnownStartingClass(cls,
866872
startingClass), startingClass, name)

0 commit comments

Comments
 (0)