Skip to content

Commit f9536e9

Browse files
authored
Merge pull request github#16883 from github/tausbn/python-fix-bad-join-in-import-resolution
Python: Fix bad join in `getImmediateModuleReference`
2 parents dfc59a4 + 446dbf6 commit f9536e9

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/ImportResolution.qll

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,12 @@ module ImportResolution {
278278
)
279279
}
280280

281+
/** Join-order helper for `getImmediateModuleReference`. */
282+
pragma[nomagic]
283+
private predicate module_reference_accesses(DataFlow::AttrRead ar, Module p, string attr_name) {
284+
ar.accesses(getModuleReference(p), attr_name)
285+
}
286+
281287
/**
282288
* Gets a dataflow node that is an immediate reference to the module `m`.
283289
*
@@ -294,16 +300,13 @@ module ImportResolution {
294300
)
295301
or
296302
// Reading an attribute on a module may return a submodule (or subpackage).
297-
exists(DataFlow::AttrRead ar, Module p, string attr_name |
298-
ar.accesses(getModuleReference(p), attr_name) and
299-
result = ar
300-
|
303+
exists(Module p, string attr_name | module_reference_accesses(result, p, attr_name) |
301304
m = getModuleFromName(p.getPackageName() + "." + attr_name)
302305
)
303306
or
304307
// This is also true for attributes that come from reexports.
305308
exists(Module reexporter, string attr_name |
306-
result.(DataFlow::AttrRead).accesses(getModuleReference(reexporter), attr_name) and
309+
module_reference_accesses(result, reexporter, attr_name) and
307310
module_reexport(reexporter, attr_name, m)
308311
)
309312
or

0 commit comments

Comments
 (0)