Python: override genEnclosingCallable

achieved flow out of functions!
This commit is contained in:
Rasmus Lerchedahl Petersen
2020-06-19 07:29:46 +02:00
parent 9669a6a4dc
commit 5a864aab87
3 changed files with 16 additions and 3 deletions

View File

@@ -122,11 +122,19 @@ class ReturnKind extends TReturnKind {
/** A data flow node that represents a value returned by a callable. */
class ReturnNode extends Node {
Return ret;
// See `TaintTrackingImplementation::returnFlowStep`
ReturnNode() { this.asCfgNode() = any(Return r).getValue().getAFlowNode() }
ReturnNode() {
this.asCfgNode() = ret.getValue().getAFlowNode()
}
/** Gets the kind of this return node. */
ReturnKind getKind() { result = TNormalReturnKind() }
override DataFlowCallable getEnclosingCallable() {
result.getScope().getAStmt() = ret // TODO: check nested function definitions
}
}
/** A data flow node that represents the output of a call. */

View File

@@ -48,7 +48,7 @@ class Node extends TNode {
}
/** Gets the enclosing callable of this node. */
final DataFlowCallable getEnclosingCallable() {
DataFlowCallable getEnclosingCallable() {
none()
}
@@ -99,13 +99,17 @@ class ParameterNode extends Node {
this.asEssaNode() instanceof ParameterDefinition
}
/**
/**
* Holds if this node is the parameter of callable `c` at the specified
* (zero-based) position.
*/
predicate isParameterOf(DataFlowCallable c, int i) {
this.asEssaNode().(ParameterDefinition).getDefiningNode() = c.getParameter(i)
}
override DataFlowCallable getEnclosingCallable() {
this.isParameterOf(result, _)
}
}
/**

View File

@@ -0,0 +1 @@
| test.py:4:10:4:10 | ControlFlowNode for z | test.py:7:5:7:20 | ControlFlowNode for obfuscated_id() |