Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 3 additions & 7 deletions python/ql/src/semmle/python/objects/Modules.qll
Original file line number Diff line number Diff line change
Expand Up @@ -177,13 +177,8 @@ class PackageObjectInternal extends ModuleObjectInternal, TPackageObject {
or
exists(Module init |
init = this.getSourceModule() and
(
/* There is no variable shadowing the name of the child module */
not exists(EssaVariable var | var.getAUse() = init.getANormalExit() and var.getSourceVariable().getName() = name)
or
/* The variable shadowing the name of the child module is undefined at exit */
ModuleAttributes::pointsToAtExit(init, name, ObjectInternal::undefined(), _)
) and
/* The variable shadowing the name of the child module is undefined at exit */
ModuleAttributes::pointsToAtExit(init, name, ObjectInternal::undefined(), _) and
not name = "__init__" and
value = this.submodule(name) and
origin = CfgOrigin::fromObject(value)
Expand Down Expand Up @@ -249,6 +244,7 @@ class PythonModuleObjectInternal extends ModuleObjectInternal, TPythonModule {
}

pragma [noinline] override predicate attribute(string name, ObjectInternal value, CfgOrigin origin) {
value != ObjectInternal::undefined() and
ModuleAttributes::pointsToAtExit(this.getSourceModule(), name, value, origin)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
| nested/__init__.py:1:6:1:12 | ControlFlowNode for ImportExpr | import | nested/nested.py:0:0:0:0 | Module nested.nested |
| nested/nested.py:1:1:1:13 | ControlFlowNode for FunctionExpr | import | nested/nested.py:1:1:1:13 | Function nested |
| test.py:1:6:1:11 | ControlFlowNode for ImportExpr | import | file://:0:0:0:0 | Package nested |
| test.py:2:1:2:6 | ControlFlowNode for nested | import | nested/nested.py:1:1:1:13 | Function nested |
7 changes: 7 additions & 0 deletions python/ql/test/library-tests/PointsTo/import_star/Values.ql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@

import python

from ControlFlowNode f, Context ctx, Value v, ControlFlowNode origin
where
f.pointsTo(ctx, v, origin)
select f, ctx, v
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
from .nested import *
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
def nested():
pass
2 changes: 2 additions & 0 deletions python/ql/test/library-tests/PointsTo/import_star/test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
from nested import *
nested
12 changes: 11 additions & 1 deletion python/ql/test/library-tests/PointsTo/new/Sanity.ql
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,17 @@ predicate ssa_sanity(string clsname, string problem, string what) {
)
}

predicate undefined_sanity(string clsname, string problem, string what) {
/* Variables may be undefined, but values cannot be */
exists(ControlFlowNode f |
PointsToInternal::pointsTo(f, _, ObjectInternal::undefined(), _) and
clsname = f.getAQlClass() and not clsname = "AnyNode" and
problem = " points-to an undefined variable" and
what = f.toString()
)
}

from string clsname, string problem, string what
where ssa_sanity(clsname, problem, what)
where ssa_sanity(clsname, problem, what) or undefined_sanity(clsname, problem, what)
select clsname, what, problem