forked from github/codeql
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtend.ql
More file actions
59 lines (50 loc) · 1.72 KB
/
Extend.ql
File metadata and controls
59 lines (50 loc) · 1.72 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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import python
import semmle.python.pointsto.PointsTo
private import semmle.python.types.Extensions
class CfgExtension extends CustomPointsToOriginFact {
CfgExtension() {
this.(NameNode).getId() = "one"
or
this.(NameNode).getId() = "two"
}
override predicate pointsTo(Object value, ClassObject cls) {
cls = theIntType() and
(
this.(NameNode).getId() = "one" and value.(NumericObject).intValue() = 1
or
this.(NameNode).getId() = "two" and value.(NumericObject).intValue() = 2
)
}
}
class AttributeExtension extends CustomPointsToAttribute {
AttributeExtension() { this = this }
override predicate attributePointsTo(
string name, Object value, ClassObject cls, ControlFlowNode origin
) {
cls = theIntType() and
origin = any(Module m).getEntryNode() and
(
name = "three" and value.(NumericObject).intValue() = 3
or
name = "four" and value.(NumericObject).intValue() = 4
)
}
}
class NoClassExtension extends CustomPointsToObjectFact {
NoClassExtension() { this = this }
override predicate pointsTo(Object value) {
this.(NameNode).getId() = "five" and value.(NumericObject).intValue() = 5
or
this.(NameNode).getId() = "six" and value.(NumericObject).intValue() = 6
}
}
/* Check that we can use old API without causing non-monotonic recursion */
class RecurseIntoOldPointsTo extends CustomPointsToOriginFact {
RecurseIntoOldPointsTo() { PointsTo::points_to(this, _, unknownValue(), _, _) }
override predicate pointsTo(Object value, ClassObject cls) {
value = unknownValue() and cls = theUnknownType()
}
}
from ControlFlowNode f, Object o
where f.getLocation().getFile().getBaseName() = "test.py" and f.refersTo(o)
select f, o.toString()