Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5a864aa

Browse files
committed
Python: override genEnclosingCallable
achieved flow out of functions!
1 parent 9669a6a commit 5a864aa

3 files changed

Lines changed: 16 additions & 3 deletions

File tree

python/ql/src/experimental/dataflow/internal/DataFlowPrivate.qll

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,11 +122,19 @@ class ReturnKind extends TReturnKind {
122122

123123
/** A data flow node that represents a value returned by a callable. */
124124
class ReturnNode extends Node {
125+
Return ret;
126+
125127
// See `TaintTrackingImplementation::returnFlowStep`
126-
ReturnNode() { this.asCfgNode() = any(Return r).getValue().getAFlowNode() }
128+
ReturnNode() {
129+
this.asCfgNode() = ret.getValue().getAFlowNode()
130+
}
127131

128132
/** Gets the kind of this return node. */
129133
ReturnKind getKind() { result = TNormalReturnKind() }
134+
135+
override DataFlowCallable getEnclosingCallable() {
136+
result.getScope().getAStmt() = ret // TODO: check nested function definitions
137+
}
130138
}
131139

132140
/** A data flow node that represents the output of a call. */

python/ql/src/experimental/dataflow/internal/DataFlowPublic.qll

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Node extends TNode {
4848
}
4949

5050
/** Gets the enclosing callable of this node. */
51-
final DataFlowCallable getEnclosingCallable() {
51+
DataFlowCallable getEnclosingCallable() {
5252
none()
5353
}
5454

@@ -99,13 +99,17 @@ class ParameterNode extends Node {
9999
this.asEssaNode() instanceof ParameterDefinition
100100
}
101101

102-
/**
102+
/**
103103
* Holds if this node is the parameter of callable `c` at the specified
104104
* (zero-based) position.
105105
*/
106106
predicate isParameterOf(DataFlowCallable c, int i) {
107107
this.asEssaNode().(ParameterDefinition).getDefiningNode() = c.getParameter(i)
108108
}
109+
110+
override DataFlowCallable getEnclosingCallable() {
111+
this.isParameterOf(result, _)
112+
}
109113
}
110114

111115
/**
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
| test.py:4:10:4:10 | ControlFlowNode for z | test.py:7:5:7:20 | ControlFlowNode for obfuscated_id() |

0 commit comments

Comments
 (0)