Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions python/ql/src/semmle/python/pointsto/Base.qll
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@ ClassObject simple_types(Object obj) {
obj.getOrigin() instanceof Module and result = theModuleType()
or
result = builtin_object_type(obj)
or
obj = unknownValue() and result = theUnknownType()
}

private ClassObject comprehension(Expr e) {
Expand Down
16 changes: 16 additions & 0 deletions python/ql/src/semmle/python/types/Extensions.qll
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
*
* This should be considered an advance feature. Modifying the points-to analysis
* can cause queries to give strange and misleading results, if not done with care.
*
* WARNING:
* This module interacts with the internals of points-to analysis and
* the classes here are more likely to change than the rest of the library.
*/

import python
Expand Down Expand Up @@ -34,6 +38,18 @@ abstract class CustomPointsToOriginFact extends CustomPointsToFact {

}

/* Custom points-to fact with inferred class */
abstract class CustomPointsToObjectFact extends CustomPointsToFact {

abstract predicate pointsTo(Object value);

override predicate pointsTo(Context context, Object value, ClassObject cls, ControlFlowNode origin) {
this.pointsTo(value) and cls = simple_types(value) and origin = this and context.appliesTo(this)
}

}


/** INTERNAL -- Do not use */
abstract class CustomPointsToAttribute extends Object {

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
| test.py:4:1:4:3 | ControlFlowNode for one | int 1 |
| test.py:5:1:5:3 | ControlFlowNode for two | int 2 |
| test.py:8:1:8:1 | ControlFlowNode for IntegerLiteral | int 1 |
| test.py:8:1:8:7 | ControlFlowNode for Tuple | Tuple |
| test.py:8:1:8:11 | ControlFlowNode for Tuple | Tuple |
| test.py:8:3:8:3 | ControlFlowNode for IntegerLiteral | int 2 |
| test.py:8:5:8:5 | ControlFlowNode for IntegerLiteral | int 3 |
| test.py:8:7:8:7 | ControlFlowNode for IntegerLiteral | int 4 |
| test.py:8:9:8:9 | ControlFlowNode for IntegerLiteral | int 5 |
| test.py:8:11:8:11 | ControlFlowNode for IntegerLiteral | int 6 |
| test.py:10:1:10:2 | ControlFlowNode for a3 | int 3 |
| test.py:10:6:10:7 | ControlFlowNode for Tuple | Tuple |
| test.py:10:6:10:13 | ControlFlowNode for Attribute | int 3 |
Expand All @@ -13,3 +15,5 @@
| test.py:11:6:11:15 | ControlFlowNode for Attribute | int 4 |
| test.py:13:1:13:2 | ControlFlowNode for a3 | int 3 |
| test.py:14:1:14:2 | ControlFlowNode for a4 | int 4 |
| test.py:16:1:16:4 | ControlFlowNode for five | int 5 |
| test.py:17:1:17:3 | ControlFlowNode for six | int 6 |
13 changes: 13 additions & 0 deletions python/ql/test/library-tests/PointsTo/extensions/Extend.ql
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,19 @@ class AttributeExtension extends CustomPointsToAttribute {

}

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
}

}


from ControlFlowNode f, Object o
where f.getLocation().getFile().getBaseName() = "test.py" and f.refersTo(o)
select f, o.toString()
Expand Down
5 changes: 4 additions & 1 deletion python/ql/test/library-tests/PointsTo/extensions/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,13 @@
two

#Make sure values exist in DB
1,2,3,4
1,2,3,4,5,6

a3 = ().three
a4 = False.four

a3
a4

five
six