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

Skip to content

Commit 3b42f3c

Browse files
committed
Python points-to/taint-tracking: Fix up flow into __init__ methods.
1 parent 53f8591 commit 3b42f3c

4 files changed

Lines changed: 11 additions & 8 deletions

File tree

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,8 @@ class PythonClassObjectInternal extends ClassObjectInternal, TPythonClassObject
9797

9898
override predicate calleeAndOffset(Function scope, int paramOffset) {
9999
exists(PythonFunctionObjectInternal init |
100-
// TO DO... Lookup init...
101-
none() |
102-
init.getScope() = scope and paramOffset = 1
100+
this.lookup("__init__", init, _) and
101+
init.calleeAndOffset(scope, paramOffset-1)
103102
)
104103
}
105104

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,5 +146,9 @@ class ClassValue extends Value {
146146
result = Types::getMro(this).getAnItem()
147147
}
148148

149+
Value lookup(string name) {
150+
this.(ClassObjectInternal).lookup(name, result, _)
151+
}
152+
149153
}
150154

python/ql/src/semmle/python/security/TaintTracking.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1069,7 +1069,7 @@ library module TaintFlowImplementation {
10691069
predicate self_init_end_transfer(EssaVariable self, CallContext callee, CallNode call, CallContext caller) {
10701070
exists(ClassValue cls, Function init |
10711071
call.getFunction().pointsTo(cls) and
1072-
init = cls.attr("__init__").(CallableValue).getScope() and
1072+
init = cls.lookup("__init__").(CallableValue).getScope() and
10731073
self.getSourceVariable().(Variable).isSelf() and self.getScope() = init
10741074
|
10751075
callee = caller.getCallee(call)
@@ -1218,7 +1218,7 @@ library module TaintFlowImplementation {
12181218
pragma [noinline]
12191219
predicate class_initializer_argument(ClassValue cls, int n, CallNode call, CallableValue func, ControlFlowNode argument, NameNode param) {
12201220
call.getFunction().pointsTo(cls) and
1221-
cls.attr("__init__") = func and
1221+
cls.lookup("__init__") = func and
12221222
call.getArg(n) = argument and
12231223
param.getNode() = func.getScope().getArg(n+1)
12241224
}
@@ -1510,7 +1510,7 @@ class CallContext extends TCallContext {
15101510
exists(ClassValue cls,CallNode call |
15111511
this = TCalleeContext(call, _, _) and
15121512
call.getFunction().pointsTo(cls) and
1513-
s = cls.attr("__init__").(CallableValue).getScope() and
1513+
s = cls.lookup("__init__").(CallableValue).getScope() and
15141514
call.getFunction().pointsTo(cls)
15151515
)
15161516
}

python/ql/src/semmle/python/types/ClassObject.qll

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ class ClassObject extends Object {
108108
Will include attributes of super-classes */
109109
Object lookupAttribute(string name) {
110110
exists(Value val |
111-
theClass().attribute(name, val, _) and
111+
theClass().lookup(name, val, _) and
112112
result = val.getSource()
113113
)
114114
}
@@ -135,7 +135,7 @@ class ClassObject extends Object {
135135
/** Whether the named attribute refers to the object, class and origin */
136136
predicate attributeRefersTo(string name, Object obj, ClassObject cls, ControlFlowNode origin) {
137137
exists(Value val, CfgOrigin valorig |
138-
theClass().attribute(name, val, valorig) and
138+
theClass().lookup(name, val, valorig) and
139139
obj = val.getSource() and
140140
cls = val.getClass().getSource() and
141141
origin = valorig.toCfgNode()

0 commit comments

Comments
 (0)