mirror of
https://github.com/github/codeql.git
synced 2025-12-17 01:03:14 +01:00
Python: Fix queries and tests
This commit is contained in:
@@ -36,7 +36,7 @@ predicate same_value(Expr left, Expr right) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
predicate maybe_defined_in_outer_scope(Name n) {
|
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())
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ predicate undefined_use_in_function(Name u) {
|
|||||||
not u.getEnclosingModule().(ImportTimeScope).definesName(u.getId()) and
|
not u.getEnclosingModule().(ImportTimeScope).definesName(u.getId()) and
|
||||||
not exists(ModuleValue m | m.getScope() = u.getEnclosingModule() | m.hasAttribute(u.getId())) and
|
not exists(ModuleValue m | m.getScope() = u.getEnclosingModule() | m.hasAttribute(u.getId())) and
|
||||||
not globallyDefinedName(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 guarded_against_name_error(u) and
|
||||||
not (u.getEnclosingModule().isPackageInit() and u.getId() = "__path__")
|
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) {
|
predicate undefined_use_in_class_or_module(Name u) {
|
||||||
exists(GlobalVariable v | u.uses(v)) and
|
exists(GlobalVariable v | u.uses(v)) and
|
||||||
not u.getScope().getScope*() instanceof Function 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 guarded_against_name_error(u) and
|
||||||
not exists(ModuleValue m | m.getScope() = u.getEnclosingModule() | m.hasAttribute(u.getId())) and
|
not exists(ModuleValue m | m.getScope() = u.getEnclosingModule() | m.hasAttribute(u.getId())) and
|
||||||
not (u.getEnclosingModule().isPackageInit() and u.getId() = "__path__") and
|
not (u.getEnclosingModule().isPackageInit() and u.getId() = "__path__") and
|
||||||
|
|||||||
@@ -18,7 +18,9 @@ private import semmle.python.types.ImportTime
|
|||||||
|
|
||||||
/* Local variable part */
|
/* Local variable part */
|
||||||
predicate initialized_as_local(PlaceHolder use) {
|
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
|
l.getVariable() instanceof LocalVariable and
|
||||||
not l.maybeUndefined()
|
not l.maybeUndefined()
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import python
|
import python
|
||||||
|
private import LegacyPointsTo
|
||||||
|
|
||||||
from SsaVariable var
|
from SsaVariableWithPointsTo var
|
||||||
where var.maybeUndefined()
|
where var.maybeUndefined()
|
||||||
select var.getDefinition().getLocation().getStartLine(), var.toString()
|
select var.getDefinition().getLocation().getStartLine(), var.toString()
|
||||||
|
|||||||
Reference in New Issue
Block a user