Skip to content

Commit 8fadb64

Browse files
committed
Python points-to: Make sure that builtin-classes inherit attributes.
1 parent af08f85 commit 8fadb64

File tree

2 files changed

+13
-5
lines changed

2 files changed

+13
-5
lines changed

python/ql/src/analysis/Sanity.ql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,15 @@ predicate file_sanity(string clsname, string problem, string what) {
212212
)
213213
}
214214

215+
predicate class_value_sanity(string clsname, string problem, string what) {
216+
exists(ClassValue value |
217+
exists(value.getASuperType().lookup(what)) and
218+
not exists(value.lookup(what)) and
219+
clsname = value.getAQlClass() and
220+
problem = "is missing attribute that superclass has"
221+
)
222+
}
223+
215224
from string clsname, string problem, string what
216225
where
217226
ast_sanity(clsname, problem, what) or
@@ -224,5 +233,6 @@ source_object_sanity(clsname, problem, what) or
224233
function_object_sanity(clsname, problem, what) or
225234
points_to_sanity(clsname, problem, what) or
226235
jump_to_definition_sanity(clsname, problem, what) or
227-
file_sanity(clsname, problem, what)
236+
file_sanity(clsname, problem, what) or
237+
class_value_sanity(clsname, problem, what)
228238
select clsname + " " + what + " has " + problem

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,8 +191,7 @@ class BuiltinClassObjectInternal extends ClassObjectInternal, TBuiltinClassObjec
191191
}
192192

193193
override predicate lookup(string name, ObjectInternal value, CfgOrigin origin) {
194-
value = ObjectInternal::fromBuiltin(this.getBuiltin().getMember(name)) and
195-
origin = CfgOrigin::unknown()
194+
Types::getMro(this).lookup(name, value, origin)
196195
}
197196

198197
pragma [noinline] override predicate attributesUnknown() { none() }
@@ -301,8 +300,7 @@ class TypeInternal extends ClassObjectInternal, TType {
301300
}
302301

303302
override predicate lookup(string name, ObjectInternal value, CfgOrigin origin) {
304-
value = ObjectInternal::fromBuiltin(Builtin::special("type").getMember(name)) and
305-
origin = CfgOrigin::unknown()
303+
Types::getMro(this).lookup(name, value, origin)
306304
}
307305

308306
pragma [noinline] override predicate attributesUnknown() { any() }

0 commit comments

Comments
 (0)