mirror of
https://github.com/github/codeql.git
synced 2026-02-23 10:23:41 +01:00
This commit removes SSA nodes from the data flow graph. Specifically, for a definition and use such as ```python x = expr y = x + 2 ``` we used to have flow from `expr` to an SSA variable representing x and from that SSA variable to the use of `x` in the definition of `y`. Now we instead have flow from `expr` to the control flow node for `x` at line 1 and from there to the control flow node for `x` at line 2. Specific changes: - `EssaNode` from the data flow layer no longer exists. - Several glue steps between `EssaNode`s and `CfgNode`s have been deleted. - Entry nodes are now admitted as `CfgNodes` in the data flow layer (they were filtered out before). - Entry nodes now have a new `toString` taking into account that the module name may be ambigous. - Some tests have been rewritten to accomodate the changes, but only `python/ql/test/experimental/dataflow/basic/maximalFlowsConfig.qll` should have semantic changes. - Comments have been updated - Test output has been updated, but apart from `python/ql/test/experimental/dataflow/basic/maximalFlows.expected` only `python/ql/test/experimental/dataflow/typetracking-summaries/summaries.py` should have a semantic change. This is a bonus fix, probably meaning that something was never connected up correctly.
48 lines
1.6 KiB
Plaintext
48 lines
1.6 KiB
Plaintext
import python
|
|
import semmle.python.dataflow.new.DataFlow
|
|
private import semmle.python.dataflow.new.internal.DataFlowPrivate as DataFlowPrivate
|
|
|
|
/** Gets the EssaNode that holds the module imported by the fully qualified module name `name` */
|
|
DataFlow::CfgNode module_import(string name) {
|
|
// exists(Variable var, Import imp, Alias alias |
|
|
// alias = imp.getAName() and
|
|
// alias.getAsname() = var.getAStore() and
|
|
// (
|
|
// name = alias.getValue().(ImportMember).getImportedModuleName()
|
|
// or
|
|
// name = alias.getValue().(ImportExpr).getImportedModuleName()
|
|
// ) and
|
|
// result.getVar().(AssignmentDefinition).getSourceVariable() = var
|
|
// )
|
|
exists(Variable var, AssignmentDefinition def, Import imp, Alias alias |
|
|
var = def.getSourceVariable() and
|
|
result.getNode() = def.getDefiningNode() and
|
|
alias = imp.getAName() and
|
|
alias.getAsname() = var.getAStore()
|
|
|
|
|
name = alias.getValue().(ImportMember).getImportedModuleName()
|
|
or
|
|
name = alias.getValue().(ImportExpr).getImportedModuleName()
|
|
)
|
|
}
|
|
|
|
query predicate os_import(DataFlow::Node node) {
|
|
node = module_import("os") and
|
|
exists(node.getLocation().getFile().getRelativePath())
|
|
}
|
|
|
|
query predicate flowstep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
|
|
os_import(nodeFrom) and
|
|
DataFlow::localFlowStep(nodeFrom, nodeTo)
|
|
}
|
|
|
|
query predicate jumpStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
|
|
os_import(nodeFrom) and
|
|
DataFlowPrivate::jumpStep(nodeFrom, nodeTo)
|
|
}
|
|
|
|
query predicate essaFlowStep(DataFlow::Node nodeFrom, DataFlow::Node nodeTo) {
|
|
os_import(nodeFrom) and
|
|
DataFlowPrivate::LocalFlow::localFlowStep(nodeFrom, nodeTo)
|
|
}
|