Merge pull request #21459 from github/tausbn/python-fix-missing-relative-imports

Python: Fix resolution of relative imports from namespace packages
This commit is contained in:
Taus
2026-03-16 14:59:44 +01:00
committed by GitHub
8 changed files with 60 additions and 0 deletions

View File

@@ -0,0 +1,5 @@
from . import helper
def use_relative():
tainted = source()
helper.process(tainted)

View File

@@ -0,0 +1,5 @@
def process(value):
sink(value) #$ flow=source
def process2(value):
sink(value) #$ flow=source

View File

@@ -0,0 +1,5 @@
from .. import helper
def use_multi_level_relative():
tainted = source()
helper.process2(tainted)

View File

@@ -0,0 +1,35 @@
import python
import semmle.python.dataflow.new.DataFlow
import semmle.python.dataflow.new.TaintTracking
import utils.test.InlineExpectationsTest
private module TestConfig implements DataFlow::ConfigSig {
predicate isSource(DataFlow::Node node) {
node.(DataFlow::CallCfgNode).getFunction().asCfgNode().(NameNode).getId() = "source"
}
predicate isSink(DataFlow::Node node) {
exists(DataFlow::CallCfgNode call |
call.getFunction().asCfgNode().(NameNode).getId() = "sink" and
node = call.getArg(0)
)
}
}
private module TestFlow = TaintTracking::Global<TestConfig>;
module FlowTest implements TestSig {
string getARelevantTag() { result = "flow" }
predicate hasActualResult(Location location, string element, string tag, string value) {
exists(DataFlow::Node sink |
TestFlow::flow(_, sink) and
tag = "flow" and
location = sink.getLocation() and
value = "source" and
element = sink.toString()
)
}
}
import MakeTest<FlowTest>