From cd1619b43e97cc6425f5f5b7e7989ef595cffd03 Mon Sep 17 00:00:00 2001 From: Taus Date: Wed, 26 Nov 2025 13:59:23 +0000 Subject: [PATCH] Python: Fix queries and tests --- python/ql/src/Statements/RedundantAssignment.ql | 2 +- python/ql/src/Variables/UndefinedGlobal.ql | 4 ++-- python/ql/src/Variables/UndefinedPlaceHolder.ql | 4 +++- .../ql/test/library-tests/ControlFlow/ssa/undefined/test.ql | 3 ++- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/python/ql/src/Statements/RedundantAssignment.ql b/python/ql/src/Statements/RedundantAssignment.ql index 357364c41b2..a443e199b1c 100644 --- a/python/ql/src/Statements/RedundantAssignment.ql +++ b/python/ql/src/Statements/RedundantAssignment.ql @@ -36,7 +36,7 @@ predicate same_value(Expr left, Expr right) { } predicate maybe_defined_in_outer_scope(Name n) { - exists(SsaVariable v | v.getAUse().getNode() = n | v.maybeUndefined()) + exists(SsaVariableWithPointsTo v | v.getAUse().getNode() = n | v.maybeUndefined()) } /* diff --git a/python/ql/src/Variables/UndefinedGlobal.ql b/python/ql/src/Variables/UndefinedGlobal.ql index 2fdf708a2b9..404ac64aa5a 100644 --- a/python/ql/src/Variables/UndefinedGlobal.ql +++ b/python/ql/src/Variables/UndefinedGlobal.ql @@ -62,7 +62,7 @@ predicate undefined_use_in_function(Name u) { not u.getEnclosingModule().(ImportTimeScope).definesName(u.getId()) and not exists(ModuleValue m | m.getScope() = u.getEnclosingModule() | m.hasAttribute(u.getId())) and not globallyDefinedName(u.getId()) and - not exists(SsaVariable var | var.getAUse().getNode() = u and not var.maybeUndefined()) and + not exists(SsaVariableWithPointsTo var | var.getAUse().getNode() = u and not var.maybeUndefined()) and not guarded_against_name_error(u) and not (u.getEnclosingModule().isPackageInit() and u.getId() = "__path__") } @@ -70,7 +70,7 @@ predicate undefined_use_in_function(Name u) { predicate undefined_use_in_class_or_module(Name u) { exists(GlobalVariable v | u.uses(v)) and not u.getScope().getScope*() instanceof Function and - exists(SsaVariable var | var.getAUse().getNode() = u | var.maybeUndefined()) and + exists(SsaVariableWithPointsTo var | var.getAUse().getNode() = u | var.maybeUndefined()) and not guarded_against_name_error(u) and not exists(ModuleValue m | m.getScope() = u.getEnclosingModule() | m.hasAttribute(u.getId())) and not (u.getEnclosingModule().isPackageInit() and u.getId() = "__path__") and diff --git a/python/ql/src/Variables/UndefinedPlaceHolder.ql b/python/ql/src/Variables/UndefinedPlaceHolder.ql index 4b21e371977..29f9b3a1a51 100644 --- a/python/ql/src/Variables/UndefinedPlaceHolder.ql +++ b/python/ql/src/Variables/UndefinedPlaceHolder.ql @@ -18,7 +18,9 @@ private import semmle.python.types.ImportTime /* Local variable part */ predicate initialized_as_local(PlaceHolder use) { - exists(SsaVariable l, Function f | f = use.getScope() and l.getAUse() = use.getAFlowNode() | + exists(SsaVariableWithPointsTo l, Function f | + f = use.getScope() and l.getAUse() = use.getAFlowNode() + | l.getVariable() instanceof LocalVariable and not l.maybeUndefined() ) diff --git a/python/ql/test/library-tests/ControlFlow/ssa/undefined/test.ql b/python/ql/test/library-tests/ControlFlow/ssa/undefined/test.ql index 41b08ec0591..c161c5d3f5e 100644 --- a/python/ql/test/library-tests/ControlFlow/ssa/undefined/test.ql +++ b/python/ql/test/library-tests/ControlFlow/ssa/undefined/test.ql @@ -1,5 +1,6 @@ import python +private import LegacyPointsTo -from SsaVariable var +from SsaVariableWithPointsTo var where var.maybeUndefined() select var.getDefinition().getLocation().getStartLine(), var.toString()