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

Skip to content

Commit 9af7071

Browse files
committed
Python points-to: track return values from builtin methods.
1 parent b8fb3e3 commit 9af7071

1 file changed

Lines changed: 18 additions & 2 deletions

File tree

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

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -274,9 +274,25 @@ class BuiltinMethodObjectInternal extends CallableObjectInternal, TBuiltinMethod
274274

275275
override predicate callResult(PointsToContext callee, ObjectInternal obj, CfgOrigin origin) { none() }
276276

277+
pragma [noinline]
277278
override predicate callResult(ObjectInternal obj, CfgOrigin origin) {
278-
// TO DO .. Result should be be a unknown value of a known class if the return type is known or just an unknown.
279-
none()
279+
exists(Builtin func, BuiltinClassObjectInternal cls |
280+
func = this.getBuiltin() and
281+
cls = ObjectInternal::fromBuiltin(this.getReturnType()) |
282+
obj = TUnknownInstance(cls)
283+
or
284+
cls = ObjectInternal::noneType() and obj = ObjectInternal::none_()
285+
or
286+
cls = ObjectInternal::builtin("bool") and obj = ObjectInternal::bool(_)
287+
) and
288+
origin = CfgOrigin::unknown()
289+
}
290+
291+
Builtin getReturnType() {
292+
exists(Builtin func |
293+
func = this.getBuiltin() |
294+
ext_rettype(func, result)
295+
)
280296
}
281297

282298
override ControlFlowNode getOrigin() {

0 commit comments

Comments
 (0)