-
Notifications
You must be signed in to change notification settings - Fork 2k
Expand file tree
/
Copy pathFilters.qll
More file actions
38 lines (34 loc) · 1.13 KB
/
Filters.qll
File metadata and controls
38 lines (34 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/**
* Helper predicates for standard tests in Python commonly
* used to filter objects by value or by type.
*/
import python
/** Holds if `c` is a call to `hasattr(obj, attr)`. */
predicate hasattr(CallNode c, ControlFlowNode obj, string attr) {
c.getFunction().getNode().(Name).getId() = "hasattr" and
c.getArg(0) = obj and
c.getArg(1).getNode().(StringLiteral).getText() = attr
}
/** Holds if `c` is a call to `isinstance(use, cls)`. */
predicate isinstance(CallNode fc, ControlFlowNode cls, ControlFlowNode use) {
fc.getFunction().(NameNode).getId() = "isinstance" and
cls = fc.getArg(1) and
fc.getArg(0) = use
}
/** Holds if `c` is a test comparing `x` and `y`. `is` is true if the operator is `is` or `==`, it is false if the operator is `is not` or `!=`. */
predicate equality_test(CompareNode c, ControlFlowNode x, boolean is, ControlFlowNode y) {
exists(Cmpop op |
c.operands(x, op, y) or
c.operands(y, op, x)
|
(
is = true and op instanceof Is
or
is = false and op instanceof IsNot
or
is = true and op instanceof Eq
or
is = false and op instanceof NotEq
)
)
}