mirror of
https://github.com/github/codeql.git
synced 2026-04-30 11:15:13 +02:00
Python: Adds modernized predicates
This commit is contained in:
@@ -268,6 +268,18 @@ class ExceptFlowNode extends ControlFlowNode {
|
||||
element_from_tuple_objectapi(tup).refersTo(obj, cls, origin)
|
||||
)
|
||||
}
|
||||
|
||||
private predicate handledObject(Value val, ClassValue cls, ControlFlowNode origin) {
|
||||
val.getClass() = cls and
|
||||
(
|
||||
this.getType().pointsTo(val, origin)
|
||||
or
|
||||
exists(Value tup |
|
||||
this.handledObject(val, ClassValue::tuple(), _) |
|
||||
element_from_tuple(tup).pointsTo(val, origin)
|
||||
)
|
||||
)
|
||||
}
|
||||
|
||||
/** Gets the inferred type(s) that are handled by this node, splitting tuples if possible. */
|
||||
pragma [noinline]
|
||||
@@ -277,6 +289,17 @@ class ExceptFlowNode extends ControlFlowNode {
|
||||
not exists(this.getNode().(ExceptStmt).getType()) and obj = theBaseExceptionType() and cls = theTypeType() and
|
||||
origin = this
|
||||
}
|
||||
|
||||
/** Gets the inferred type(s) that are handled by this node, splitting tuples if possible. */
|
||||
pragma [noinline]
|
||||
predicate handledException(Value val, ClassValue cls, ControlFlowNode origin) {
|
||||
this.handledObject(val, cls, origin) and not cls = ClassValue::tuple()
|
||||
or
|
||||
not exists(this.getNode().(ExceptStmt).getType()) and val = ClassValue::baseException() and cls = ClassValue::type() and
|
||||
origin = this
|
||||
}
|
||||
|
||||
|
||||
|
||||
/** Whether this `except` handles `cls` */
|
||||
predicate handles(ClassObject cls) {
|
||||
@@ -294,6 +317,12 @@ private ControlFlowNode element_from_tuple_objectapi(Object tuple) {
|
||||
)
|
||||
}
|
||||
|
||||
private ControlFlowNode element_from_tuple(Value tuple) {
|
||||
exists(Expr x, Tuple t |
|
||||
x.pointsTo(tuple,t) and result = t.getAnElt().getAFlowNode()
|
||||
)
|
||||
}
|
||||
|
||||
/** A Reraising node is the node at the end of a finally block (on the exceptional branch)
|
||||
* that reraises the current exception.
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user