Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit f7edbcc

Browse files
committed
Python points-to: Clean up interface, and deprecate old interface.
1 parent d3762ac commit f7edbcc

18 files changed

Lines changed: 257 additions & 189 deletions

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import python
2-
private import semmle.python.pointsto.PointsTo2
2+
private import semmle.python.pointsto.PointsTo
33

44
/** An expression */
55
class Expr extends Expr_, AstNode {
@@ -86,7 +86,7 @@ class Expr extends Expr_, AstNode {
8686
*/
8787
predicate refersTo(Context context, Object obj, ClassObject cls, AstNode origin) {
8888
exists(Value value, ControlFlowNode cfgorigin |
89-
PointsTo2::pointsTo(this.getAFlowNode(), context, value, cfgorigin) and
89+
PointsTo::pointsTo(this.getAFlowNode(), context, value, cfgorigin) and
9090
origin.getAFlowNode() = cfgorigin and
9191
cls = value.getClass().getSource() |
9292
if exists(value.getSource()) then
@@ -102,7 +102,7 @@ class Expr extends Expr_, AstNode {
102102
*/
103103
predicate refersTo(Object obj, AstNode origin) {
104104
exists(Value value, ControlFlowNode cfgorigin |
105-
PointsTo2::pointsTo(this.getAFlowNode(), _, value, cfgorigin) and
105+
PointsTo::pointsTo(this.getAFlowNode(), _, value, cfgorigin) and
106106
origin.getAFlowNode() = cfgorigin and
107107
if exists(value.getSource()) then
108108
obj = value.getSource()

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import python
22
import semmle.python.flow.NameNode
3-
private import semmle.python.pointsto.PointsTo2
3+
private import semmle.python.pointsto.PointsTo
44

55

66
/* Note about matching parent and child nodes and CFG splitting:
@@ -224,7 +224,7 @@ class ControlFlowNode extends @py_flow_node {
224224

225225
/** The value and origin that this ControlFlowNode points-to, given the context. */
226226
predicate pointsTo(Context context, Value value, ControlFlowNode origin) {
227-
PointsTo2::pointsTo(this, context, value, origin)
227+
PointsTo::pointsTo(this, context, value, origin)
228228
}
229229

230230
/** Gets what this flow node might "refer-to". Performs a combination of localized (intra-procedural) points-to
@@ -240,7 +240,7 @@ class ControlFlowNode extends @py_flow_node {
240240
*/
241241
predicate refersTo(Context context, Object obj, ClassObject cls, ControlFlowNode origin) {
242242
exists(Value value |
243-
PointsTo2::pointsTo(this, context, value, origin) and
243+
PointsTo::pointsTo(this, context, value, origin) and
244244
cls = value.getClass().getSource() |
245245
if exists(value.getSource().(Object)) then
246246
obj = value.getSource()
@@ -255,7 +255,7 @@ class ControlFlowNode extends @py_flow_node {
255255
*/
256256
predicate refersTo(Object obj, ControlFlowNode origin) {
257257
exists(Value value |
258-
PointsTo2::pointsTo(this, _, value, origin) |
258+
PointsTo::pointsTo(this, _, value, origin) |
259259
if exists(value.getSource().(Object)) then
260260
obj = value.getSource()
261261
else

python/ql/src/semmle/python/objects/Callables.qll

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import python
33

44
private import semmle.python.objects.TObject
55
private import semmle.python.objects.ObjectInternal
6-
private import semmle.python.pointsto.PointsTo2
6+
private import semmle.python.pointsto.PointsTo
77
private import semmle.python.pointsto.PointsToContext
88
private import semmle.python.pointsto.MRO2
99
private import semmle.python.types.Builtins
@@ -42,6 +42,10 @@ abstract class CallableObjectInternal extends ObjectInternal {
4242

4343
override predicate binds(ObjectInternal instance, string name, ObjectInternal descriptor) { none() }
4444

45+
abstract CallNode getACall(PointsToContext ctx);
46+
47+
CallNode getACall() { result = this.getACall(_) }
48+
4549
}
4650

4751

@@ -81,11 +85,11 @@ class PythonFunctionObjectInternal extends CallableObjectInternal, TPythonFuncti
8185
func = this.getScope() and
8286
callee.appliesToScope(func) |
8387
rval = func.getAReturnValueFlowNode() and
84-
PointsTo2::pointsTo(rval, callee, obj, origin)
88+
PointsToInternal::pointsTo(rval, callee, obj, origin)
8589
or
8690
exists(Return ret |
8791
ret.getScope() = func and
88-
PointsTo2::reachableBlock(ret.getAFlowNode().getBasicBlock(), callee) and
92+
PointsToInternal::reachableBlock(ret.getAFlowNode().getBasicBlock(), callee) and
8993
not exists(ret.getValue()) and
9094
obj = ObjectInternal::none_() and
9195
origin = CfgOrigin::unknown()
@@ -113,6 +117,14 @@ class PythonFunctionObjectInternal extends CallableObjectInternal, TPythonFuncti
113117
value = TBoundMethod(instance, this) and origin = CfgOrigin::unknown()
114118
}
115119

120+
override CallNode getACall(PointsToContext ctx) {
121+
PointsTo::pointsTo(result.getFunction(), ctx, this, _)
122+
or
123+
exists(BoundMethodObjectInternal bm |
124+
bm.getACall() = result and this = bm.getFunction()
125+
)
126+
}
127+
116128
}
117129

118130
class BuiltinFunctionObjectInternal extends CallableObjectInternal, TBuiltinFunctionObject {
@@ -192,6 +204,10 @@ class BuiltinFunctionObjectInternal extends CallableObjectInternal, TBuiltinFunc
192204

193205
override predicate descriptorGet(ObjectInternal instance, ObjectInternal value, CfgOrigin origin) { none() }
194206

207+
override CallNode getACall(PointsToContext ctx) {
208+
PointsTo::pointsTo(result.getFunction(), ctx, this, _)
209+
}
210+
195211

196212
}
197213

@@ -248,6 +264,10 @@ class BuiltinMethodObjectInternal extends CallableObjectInternal, TBuiltinMethod
248264
value = this and origin = CfgOrigin::unknown()
249265
}
250266

267+
override CallNode getACall(PointsToContext ctx) {
268+
PointsTo::pointsTo(result.getFunction(), ctx, this, _)
269+
}
270+
251271
}
252272

253273
class BoundMethodObjectInternal extends CallableObjectInternal, TBoundMethod {
@@ -307,6 +327,10 @@ class BoundMethodObjectInternal extends CallableObjectInternal, TBoundMethod {
307327

308328
override predicate descriptorGet(ObjectInternal instance, ObjectInternal value, CfgOrigin origin) { none() }
309329

330+
override CallNode getACall(PointsToContext ctx) {
331+
PointsTo::pointsTo(result.getFunction(), ctx, this, _)
332+
}
333+
310334
}
311335

312336
class ClassMethodObjectInternal extends ObjectInternal, TClassMethod {

python/ql/src/semmle/python/objects/Classes.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import python
33

44
private import semmle.python.objects.TObject
55
private import semmle.python.objects.ObjectInternal
6-
private import semmle.python.pointsto.PointsTo2
6+
private import semmle.python.pointsto.PointsTo
77
private import semmle.python.pointsto.PointsToContext
88
private import semmle.python.pointsto.MRO2
99
private import semmle.python.types.Builtins
@@ -39,7 +39,7 @@ abstract class ClassObjectInternal extends ObjectInternal {
3939

4040
override predicate binds(ObjectInternal instance, string name, ObjectInternal descriptor) {
4141
instance = this and
42-
PointsTo2::attributeRequired(this, name) and
42+
PointsToInternal::attributeRequired(this, name) and
4343
this.attribute(name, descriptor, _) and
4444
descriptor.isDescriptor() = true
4545
}
@@ -236,7 +236,7 @@ class TypeInternal extends ClassObjectInternal, TType {
236236
exists(CallNode call, PointsToContext caller, ObjectInternal instance |
237237
callee.fromCall(call, caller) |
238238
count(call.getAnArg()) = 1 and
239-
PointsTo2::pointsTo(call.getArg(0), caller, instance, origin) and
239+
PointsToInternal::pointsTo(call.getArg(0), caller, instance, origin) and
240240
obj = instance.getClass()
241241
)
242242
}

python/ql/src/semmle/python/objects/Constants.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import python
22

33
private import semmle.python.objects.TObject
44
private import semmle.python.objects.ObjectInternal
5-
private import semmle.python.pointsto.PointsTo2
5+
private import semmle.python.pointsto.PointsTo
66
private import semmle.python.pointsto.MRO2
77
private import semmle.python.pointsto.PointsToContext
88
private import semmle.python.types.Builtins

python/ql/src/semmle/python/objects/Instances.qll

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import python
33

44
private import semmle.python.objects.TObject
55
private import semmle.python.objects.ObjectInternal
6-
private import semmle.python.pointsto.PointsTo2
6+
private import semmle.python.pointsto.PointsTo
77
private import semmle.python.pointsto.MRO2
88
private import semmle.python.pointsto.PointsToContext
99
private import semmle.python.types.Builtins
@@ -77,7 +77,7 @@ class SpecificInstanceInternal extends TSpecificInstance, ObjectInternal {
7777
}
7878

7979
override predicate attribute(string name, ObjectInternal value, CfgOrigin origin) {
80-
PointsTo2::attributeRequired(this, name) and
80+
PointsToInternal::attributeRequired(this, name) and
8181
instance_getattr(this, Types::getMro(this.getClass()), name, value, origin)
8282
}
8383

@@ -90,7 +90,7 @@ class SpecificInstanceInternal extends TSpecificInstance, ObjectInternal {
9090
override predicate binds(ObjectInternal instance, string name, ObjectInternal descriptor) {
9191
this = instance and descriptor.isDescriptor() = true and
9292
exists(AttrNode attr |
93-
PointsTo2::pointsTo(attr.getObject(name), _, instance, _) and
93+
PointsToInternal::pointsTo(attr.getObject(name), _, instance, _) and
9494
this.getClass().attribute(name, descriptor, _)
9595
)
9696
}
@@ -186,7 +186,7 @@ class SelfInstanceInternal extends TSelfInstance, ObjectInternal {
186186
}
187187

188188
override predicate attribute(string name, ObjectInternal value, CfgOrigin origin) {
189-
PointsTo2::attributeRequired(this, name) and
189+
PointsToInternal::attributeRequired(this, name) and
190190
instance_getattr(this, Types::getMro(this.getClass()), name, value, origin)
191191
}
192192

@@ -200,7 +200,7 @@ class SelfInstanceInternal extends TSelfInstance, ObjectInternal {
200200
descriptor.isDescriptor() = true and
201201
this = instance and
202202
exists(AttrNode attr |
203-
PointsTo2::pointsTo(attr.getObject(name), _, this, _) and
203+
PointsToInternal::pointsTo(attr.getObject(name), _, this, _) and
204204
this.getClass().attribute(name, descriptor, _)
205205
)
206206
}
@@ -277,7 +277,7 @@ class UnknownInstanceInternal extends TUnknownInstance, ObjectInternal {
277277
}
278278

279279
override predicate attribute(string name, ObjectInternal value, CfgOrigin origin) {
280-
PointsTo2::attributeRequired(this, name) and
280+
PointsToInternal::attributeRequired(this, name) and
281281
instance_getattr(this, Types::getMro(this.getClass()), name, value, origin)
282282
}
283283

@@ -291,7 +291,7 @@ class UnknownInstanceInternal extends TUnknownInstance, ObjectInternal {
291291
descriptor.isDescriptor() = true and
292292
this = instance and
293293
exists(AttrNode attr |
294-
PointsTo2::pointsTo(attr.getObject(name), _, this, _) and
294+
PointsToInternal::pointsTo(attr.getObject(name), _, this, _) and
295295
this.getClass().attribute(name, descriptor, _)
296296
)
297297
}
@@ -355,7 +355,7 @@ class SuperInstance extends TSuperInstance, ObjectInternal {
355355
override predicate descriptorGet(ObjectInternal instance, ObjectInternal value, CfgOrigin origin) { none() }
356356

357357
override predicate attribute(string name, ObjectInternal value, CfgOrigin origin) {
358-
PointsTo2::attributeRequired(this, name) and
358+
PointsToInternal::attributeRequired(this, name) and
359359
instance_getattr(this.getSelf(), this.getMro(), name, value, origin)
360360
}
361361

@@ -366,7 +366,7 @@ class SuperInstance extends TSuperInstance, ObjectInternal {
366366
override predicate binds(ObjectInternal instance, string name, ObjectInternal descriptor) {
367367
descriptor.isDescriptor() = true and
368368
exists(AttrNode attr |
369-
PointsTo2::pointsTo(attr.getObject(name), _, this, _) and
369+
PointsToInternal::pointsTo(attr.getObject(name), _, this, _) and
370370
instance = this.getSelf() and
371371
Types::declaredAttribute(this.getMro().findDeclaringClass(name), name, descriptor, _)
372372
)

python/ql/src/semmle/python/objects/Modules.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import python
22

33
private import semmle.python.objects.TObject
44
private import semmle.python.objects.ObjectInternal
5-
private import semmle.python.pointsto.PointsTo2
5+
private import semmle.python.pointsto.PointsTo
66
private import semmle.python.pointsto.MRO2
77
private import semmle.python.pointsto.PointsToContext
88
private import semmle.python.types.Builtins
@@ -233,7 +233,7 @@ class PythonModuleObjectInternal extends ModuleObjectInternal, TPythonModule {
233233
exists(EssaVariable var, ControlFlowNode exit, PointsToContext imp |
234234
exit = this.getSourceModule().getANormalExit() and var.getAUse() = exit and
235235
var.getSourceVariable().getName() = name and
236-
PointsTo2::ssa_variable_pointsTo(var, imp, value, origin) and
236+
PointsTo::variablePointsTo(var, imp, value, origin) and
237237
imp.isImport() and
238238
value != ObjectInternal::undefined()
239239
)
@@ -242,7 +242,7 @@ class PythonModuleObjectInternal extends ModuleObjectInternal, TPythonModule {
242242
//not exists(EssaVariable var | var.getAUse() = m.getANormalExit() and var.getSourceVariable().getName() = name) and
243243
//exists(EssaVariable var, PointsToContext imp |
244244
// var.getAUse() = m.getANormalExit() and isModuleStateVariable(var) |
245-
// PointsTo2::ssa_variable_named_attribute_pointsTo(var, imp, name, obj, origin) and
245+
// PointsToInternal::ssa_variable_named_attribute_pointsTo(var, imp, name, obj, origin) and
246246
// imp.isImport() and obj != ObjectInternal::undefined()
247247
//)
248248
}

python/ql/src/semmle/python/objects/ObjectAPI.qll

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import python
22
private import TObject
33
private import semmle.python.objects.ObjectInternal
4-
private import semmle.python.pointsto.PointsTo2
4+
private import semmle.python.pointsto.PointsTo
55
private import semmle.python.pointsto.PointsToContext
66

77
class ObjectSource = Object;
@@ -19,22 +19,31 @@ class Value extends TObject {
1919
}
2020

2121
ControlFlowNode getAReference() {
22-
PointsTo2::pointsTo(result, _, this, _)
22+
PointsToInternal::pointsTo(result, _, this, _)
2323
}
2424

2525
predicate pointsTo(ControlFlowNode node, PointsToContext context, ControlFlowNode origin) {
26-
PointsTo2::pointsTo(node, context, this, origin)
26+
PointsToInternal::pointsTo(node, context, this, origin)
2727
}
2828

2929
Value getClass() {
3030
result = this.(ObjectInternal).getClass()
3131
}
3232

3333
CallNode getACall() {
34-
PointsTo2::pointsTo(result.getFunction(), _, this, _)
34+
PointsToInternal::pointsTo(result.getFunction(), _, this, _)
3535
or
3636
exists(BoundMethodObjectInternal bm |
37-
PointsTo2::pointsTo(result.getFunction(), _, bm, _) and
37+
PointsToInternal::pointsTo(result.getFunction(), _, bm, _) and
38+
bm.getFunction() = this
39+
)
40+
}
41+
42+
CallNode getACall(PointsToContext caller) {
43+
PointsToInternal::pointsTo(result.getFunction(), caller, this, _)
44+
or
45+
exists(BoundMethodObjectInternal bm |
46+
PointsToInternal::pointsTo(result.getFunction(), caller, bm, _) and
3847
bm.getFunction() = this
3948
)
4049
}

python/ql/src/semmle/python/objects/ObjectInternal.qll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import python
22

33
private import semmle.python.objects.TObject
4-
private import semmle.python.pointsto.PointsTo2
4+
private import semmle.python.pointsto.PointsTo
55
private import semmle.python.pointsto.MRO2
66
private import semmle.python.pointsto.PointsToContext
77
private import semmle.python.types.Builtins

python/ql/src/semmle/python/objects/Sequences.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import python
66

77
private import semmle.python.objects.TObject
88
private import semmle.python.objects.ObjectInternal
9-
private import semmle.python.pointsto.PointsTo2
9+
private import semmle.python.pointsto.PointsTo
1010
private import semmle.python.pointsto.PointsToContext
1111
private import semmle.python.pointsto.MRO2
1212
private import semmle.python.types.Builtins
@@ -125,7 +125,7 @@ class PythonTupleObjectInternal extends TPythonTuple, TupleObjectInternal {
125125
override ObjectInternal getItem(int n) {
126126
exists(TupleNode t, PointsToContext context |
127127
this = TPythonTuple(t, context) and
128-
PointsTo2::pointsTo(t.getElement(n), context, result, _)
128+
PointsToInternal::pointsTo(t.getElement(n), context, result, _)
129129
)
130130
}
131131

0 commit comments

Comments
 (0)