diff --git a/python/ql/lib/semmle/python/essa/Definitions.qll b/python/ql/lib/semmle/python/essa/Definitions.qll index d9426fc5612..17b4e622ea1 100644 --- a/python/ql/lib/semmle/python/essa/Definitions.qll +++ b/python/ql/lib/semmle/python/essa/Definitions.qll @@ -276,6 +276,17 @@ class ModuleVariable extends SsaSourceVariable instanceof GlobalVariable { override CallNode redefinedAtCallSite() { none() } } +/** Holds if `f` is an import of the form `from .[...] import ...` and the enclosing scope is an __init__ module */ +private predicate import_from_dot_in_init(ImportExprNode f) { + f.getScope() = any(Module m).getInitModule() and + ( + f.getNode().getLevel() = 1 and + not exists(f.getNode().getName()) + or + f.getNode().getImportedModuleName() = f.getEnclosingModule().getPackage().getName() + ) +} + class NonEscapingGlobalVariable extends ModuleVariable { NonEscapingGlobalVariable() { this instanceof GlobalVariable and diff --git a/python/ql/lib/semmle/python/essa/SsaDefinitions.qll b/python/ql/lib/semmle/python/essa/SsaDefinitions.qll index 2b15f1a2ab2..b263287d05d 100644 --- a/python/ql/lib/semmle/python/essa/SsaDefinitions.qll +++ b/python/ql/lib/semmle/python/essa/SsaDefinitions.qll @@ -7,6 +7,13 @@ import python private import semmle.python.internal.CachedStages private import LegacyPointsTo +/** Hold if `expr` is a test (a branch) and `use` is within that test */ +predicate test_contains(ControlFlowNode expr, ControlFlowNode use) { + expr.getNode() instanceof Expr and + expr.isBranch() and + expr.getAChild*() = use +} + cached module SsaSource { /** Holds if `v` is used as the receiver in a method call. */ diff --git a/python/ql/lib/semmle/python/pointsto/Base.qll b/python/ql/lib/semmle/python/pointsto/Base.qll index c3f10778cda..bf159c4b559 100644 --- a/python/ql/lib/semmle/python/pointsto/Base.qll +++ b/python/ql/lib/semmle/python/pointsto/Base.qll @@ -44,24 +44,6 @@ private predicate class_defines_name(Class cls, string name) { exists(SsaVariable var | name = var.getId() and var.getAUse() = cls.getANormalExit()) } -/** Hold if `expr` is a test (a branch) and `use` is within that test */ -predicate test_contains(ControlFlowNode expr, ControlFlowNode use) { - expr.getNode() instanceof Expr and - expr.isBranch() and - expr.getAChild*() = use -} - -/** Holds if `f` is an import of the form `from .[...] import ...` and the enclosing scope is an __init__ module */ -predicate import_from_dot_in_init(ImportExprNode f) { - f.getScope() = any(Module m).getInitModule() and - ( - f.getNode().getLevel() = 1 and - not exists(f.getNode().getName()) - or - f.getNode().getImportedModuleName() = f.getEnclosingModule().getPackage().getName() - ) -} - /** Gets the pseudo-object representing the value referred to by an undefined variable */ Object undefinedVariable() { py_special_objects(result, "_semmle_undefined_value") }