Skip to content

Commit 5e8ab92

Browse files
committed
Add test for attribute points-to extension.
1 parent 01a2add commit 5e8ab92

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

python/ql/test/library-tests/PointsTo/extensions/Extend.expected

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,11 @@
55
| test.py:8:3:8:3 | ControlFlowNode for IntegerLiteral | int 2 |
66
| test.py:8:5:8:5 | ControlFlowNode for IntegerLiteral | int 3 |
77
| test.py:8:7:8:7 | ControlFlowNode for IntegerLiteral | int 4 |
8+
| test.py:10:1:10:2 | ControlFlowNode for a3 | int 3 |
9+
| test.py:10:6:10:7 | ControlFlowNode for Str | str u'' |
10+
| test.py:10:6:10:13 | ControlFlowNode for Attribute | int 3 |
11+
| test.py:11:1:11:2 | ControlFlowNode for a4 | int 4 |
12+
| test.py:11:6:11:10 | ControlFlowNode for False | bool False |
13+
| test.py:11:6:11:15 | ControlFlowNode for Attribute | int 4 |
14+
| test.py:13:1:13:2 | ControlFlowNode for a3 | int 3 |
15+
| test.py:14:1:14:2 | ControlFlowNode for a4 | int 4 |

python/ql/test/library-tests/PointsTo/extensions/Extend.ql

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import python
55
private import semmle.python.types.Extensions
66

77

8-
class CfgExtension extends CustomPointsToOriginFact {
8+
class CfgExtension extends CustomPointsToOriginFact {
99

1010
CfgExtension() {
1111
this.(NameNode).getId() = "one"
@@ -23,6 +23,21 @@ class CfgExtension extends CustomPointsToOriginFact {
2323
}
2424
}
2525

26+
class AttributeExtension extends CustomPointsToAttribute {
27+
28+
AttributeExtension() { any() }
29+
30+
override predicate attributePointsTo(string name, Object value, ClassObject cls, ControlFlowNode origin) {
31+
cls = theIntType() and origin = any(Module m).getEntryNode() and
32+
(
33+
name = "three" and value.(NumericObject).intValue() = 3
34+
or
35+
name = "four" and value.(NumericObject).intValue() = 4
36+
)
37+
}
38+
39+
}
40+
2641
from ControlFlowNode f, Object o
2742
where f.getLocation().getFile().getBaseName() = "test.py" and f.refersTo(o)
2843
select f, o.toString()

python/ql/test/library-tests/PointsTo/extensions/test.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,3 +6,9 @@
66

77
#Make sure values exist in DB
88
1,2,3,4
9+
10+
a3 = "".three
11+
a4 = False.four
12+
13+
a3
14+
a4

0 commit comments

Comments
 (0)