Skip to content

Commit c4a79c2

Browse files
committed
Python: Add failing tests for undefined variable as value and nested 'from import *'.
1 parent 8b58b80 commit c4a79c2

File tree

6 files changed

+27
-1
lines changed

6 files changed

+27
-1
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
| nested/__init__.py:1:6:1:12 | ControlFlowNode for ImportExpr | import | nested/nested.py:0:0:0:0 | Module nested.nested |
2+
| nested/nested.py:1:1:1:13 | ControlFlowNode for FunctionExpr | import | nested/nested.py:1:1:1:13 | Function nested |
3+
| test.py:1:6:1:11 | ControlFlowNode for ImportExpr | import | file://:0:0:0:0 | Package nested |
4+
| test.py:2:1:2:6 | ControlFlowNode for nested | import | nested/nested.py:1:1:1:13 | Function nested |
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
import python
3+
4+
from ControlFlowNode f, Context ctx, Value v, ControlFlowNode origin
5+
where
6+
f.pointsTo(ctx, v, origin)
7+
select f, ctx, v
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .nested import *
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def nested():
2+
pass
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
from nested import *
2+
nested

python/ql/test/library-tests/PointsTo/new/Sanity.ql

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,17 @@ predicate ssa_sanity(string clsname, string problem, string what) {
109109
)
110110
}
111111

112+
predicate undefined_sanity(string clsname, string problem, string what) {
113+
/* Variables may be undefined, but values cannot be */
114+
exists(ControlFlowNode f |
115+
PointsToInternal::pointsTo(f, _, ObjectInternal::undefined(), _) and
116+
clsname = f.getAQlClass() and not clsname = "AnyNode" and
117+
problem = " points-to an undefined variable" and
118+
what = f.toString()
119+
)
120+
}
121+
112122
from string clsname, string problem, string what
113-
where ssa_sanity(clsname, problem, what)
123+
where ssa_sanity(clsname, problem, what) or undefined_sanity(clsname, problem, what)
114124
select clsname, what, problem
115125

0 commit comments

Comments
 (0)