mirror of
https://github.com/github/codeql.git
synced 2026-04-30 19:26:02 +02:00
Initial commit of Python queries and QL libraries.
This commit is contained in:
committed by
Mark Shannon
parent
90c75cd362
commit
5f58824d1b
27
python/ql/src/Classes/InconsistentMRO.ql
Normal file
27
python/ql/src/Classes/InconsistentMRO.ql
Normal file
@@ -0,0 +1,27 @@
|
||||
/**
|
||||
* @name Inconsistent method resolution order
|
||||
* @description Class definition will raise a type error at runtime due to inconsistent method resolution order(MRO)
|
||||
* @kind problem
|
||||
* @tags reliability
|
||||
* correctness
|
||||
* @problem.severity error
|
||||
* @sub-severity high
|
||||
* @precision very-high
|
||||
* @id py/inconsistent-mro
|
||||
*/
|
||||
|
||||
import python
|
||||
|
||||
ClassObject left_base(ClassObject type, ClassObject base) {
|
||||
exists(int i | i > 0 and type.getBaseType(i) = base and result = type.getBaseType(i-1))
|
||||
}
|
||||
|
||||
predicate invalid_mro(ClassObject t, ClassObject left, ClassObject right) {
|
||||
t.isNewStyle() and
|
||||
left = left_base(t, right) and left = right.getAnImproperSuperType()
|
||||
}
|
||||
|
||||
from ClassObject t, ClassObject left, ClassObject right
|
||||
where invalid_mro(t, left, right)
|
||||
select t, "Construction of class " + t.getName() + " can fail due to invalid method resolution order(MRO) for bases $@ and $@.",
|
||||
left, left.getName(), right, right.getName()
|
||||
Reference in New Issue
Block a user