зеркало из https://github.com/github/codeql.git
Merge pull request #1405 from markshannon/python-fix-import-analysis
Python: Fix up 'import failure' analysis query.
This commit is contained in:
Коммит
f7a092882b
|
@ -57,15 +57,37 @@ predicate ok_to_fail(ImportExpr ie) {
|
|||
os_specific_import(ie) != get_os()
|
||||
}
|
||||
|
||||
|
||||
class VersionTest extends @py_flow_node {
|
||||
|
||||
VersionTest() {
|
||||
exists(string name |
|
||||
name.matches("%version%") and
|
||||
this.(CompareNode).getAChild+().pointsTo(Module::named("sys").attr(name))
|
||||
)
|
||||
}
|
||||
|
||||
string toString() {
|
||||
result = "VersionTest"
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/** A guard on the version of the Python interpreter */
|
||||
class VersionGuard extends ConditionBlock {
|
||||
|
||||
VersionGuard() {
|
||||
this.getLastNode() instanceof VersionTest
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
from ImportExpr ie
|
||||
where not ie.refersTo(_) and
|
||||
exists(Context c | c.appliesTo(ie.getAFlowNode())) and
|
||||
not ok_to_fail(ie) and
|
||||
not exists(VersionGuard guard |
|
||||
if guard.isTrue() then
|
||||
guard.controls(ie.getAFlowNode().getBasicBlock(), false)
|
||||
else
|
||||
guard.controls(ie.getAFlowNode().getBasicBlock(), true)
|
||||
guard.controls(ie.getAFlowNode().getBasicBlock(), _)
|
||||
)
|
||||
|
||||
select ie, "Unable to resolve import of '" + ie.getImportedModuleName() + "'."
|
||||
|
|
Загрузка…
Ссылка в новой задаче