Skip to content

Commit d2e760f

Browse files
committed
Python: Add test for missing relative import in namespace packages
1 parent a2f45f1 commit d2e760f

File tree

5 files changed

+44
-0
lines changed

5 files changed

+44
-0
lines changed
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
semmle-extractor-options: -R ./pkg
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
from . import helper
2+
3+
def use_relative():
4+
tainted = source()
5+
helper.process(tainted)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def process(value):
2+
sink(value) #$ MISSING: prints=source
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import python
2+
import semmle.python.dataflow.new.DataFlow
3+
import semmle.python.dataflow.new.TaintTracking
4+
import utils.test.InlineExpectationsTest
5+
6+
private module TestConfig implements DataFlow::ConfigSig {
7+
predicate isSource(DataFlow::Node node) {
8+
node.(DataFlow::CallCfgNode).getFunction().asCfgNode().(NameNode).getId() = "source"
9+
}
10+
11+
predicate isSink(DataFlow::Node node) {
12+
exists(DataFlow::CallCfgNode call |
13+
call.getFunction().asCfgNode().(NameNode).getId() = "sink" and
14+
node = call.getArg(0)
15+
)
16+
}
17+
}
18+
19+
private module TestFlow = TaintTracking::Global<TestConfig>;
20+
21+
module FlowTest implements TestSig {
22+
string getARelevantTag() { result = "prints" }
23+
24+
predicate hasActualResult(Location location, string element, string tag, string value) {
25+
exists(DataFlow::Node sink |
26+
TestFlow::flow(_, sink) and
27+
tag = "prints" and
28+
location = sink.getLocation() and
29+
value = "source" and
30+
element = sink.toString()
31+
)
32+
}
33+
}
34+
35+
import MakeTest<FlowTest>

0 commit comments

Comments
 (0)