Skip to content

Commit 6a79e0a

Browse files
committed
Python points-to: Prevent bad magic on 'refersTo' member predicates.
1 parent 8d4a8a6 commit 6a79e0a

File tree

2 files changed

+6
-17
lines changed

2 files changed

+6
-17
lines changed

python/ql/src/semmle/python/Exprs.qll

Lines changed: 3 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -85,30 +85,16 @@ class Expr extends Expr_, AstNode {
8585
/** Gets what this expression might "refer-to" in the given `context`.
8686
*/
8787
predicate refersTo(Context context, Object obj, ClassObject cls, AstNode origin) {
88-
exists(Value value, ControlFlowNode cfgorigin |
89-
PointsTo::pointsTo(this.getAFlowNode(), context, value, cfgorigin) and
90-
origin.getAFlowNode() = cfgorigin and
91-
cls = value.getClass().getSource() |
92-
if exists(value.getSource()) then
93-
obj = value.getSource()
94-
else
95-
obj = cfgorigin
96-
)
88+
this.getAFlowNode().refersTo(context, obj, cls, origin.getAFlowNode())
9789
}
9890

9991
/** Whether this expression might "refer-to" to `value` which is from `origin`
10092
* Unlike `this.refersTo(value, _, origin)`, this predicate includes results
10193
* where the class cannot be inferred.
10294
*/
95+
pragma[nomagic]
10396
predicate refersTo(Object obj, AstNode origin) {
104-
exists(Value value, ControlFlowNode cfgorigin |
105-
PointsTo::pointsTo(this.getAFlowNode(), _, value, cfgorigin) and
106-
origin.getAFlowNode() = cfgorigin and
107-
if exists(value.getSource()) then
108-
obj = value.getSource()
109-
else
110-
obj = cfgorigin
111-
)
97+
this.getAFlowNode().refersTo(obj, origin.getAFlowNode())
11298
}
11399

114100
/** Equivalent to `this.refersTo(value, _)` */

python/ql/src/semmle/python/Flow.qll

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,14 @@ class ControlFlowNode extends @py_flow_node {
237237
* precise, but may not provide information for a significant number of flow-nodes.
238238
* If the class is unimportant then use `refersTo(value)` or `refersTo(value, origin)` instead.
239239
*/
240+
pragma [nomagic]
240241
predicate refersTo(Object obj, ClassObject cls, ControlFlowNode origin) {
241242
this.refersTo(_, obj, cls, origin)
242243
}
243244

244245
/** Gets what this expression might "refer-to" in the given `context`.
245246
*/
247+
pragma [nomagic]
246248
predicate refersTo(Context context, Object obj, ClassObject cls, ControlFlowNode origin) {
247249
not obj = unknownValue() and
248250
not cls = theUnknownType() and
@@ -253,6 +255,7 @@ class ControlFlowNode extends @py_flow_node {
253255
* Unlike `this.refersTo(value, _, origin)` this predicate includes results
254256
* where the class cannot be inferred.
255257
*/
258+
pragma [nomagic]
256259
predicate refersTo(Object obj, ControlFlowNode origin) {
257260
not obj = unknownValue() and
258261
PointsTo::points_to(this, _, obj, _, origin)

0 commit comments

Comments
 (0)