mirror of
https://github.com/github/codeql.git
synced 2025-12-21 03:06:31 +01:00
Python: Fix module level flow for iterable unpacking
(and for * patterns in match)
Since `PhaseDependentFlow` uses the following predicate, that relies on
.getScope() to be present for there to be any importTimeFlow (flow at
toplevel scope), it's important that data-flow nodes implement `.getScope`.
```
private predicate isTopLevel(Node node) { node.getScope() instanceof Module }
```
By implementing getScope, we can now rely on default implementation of
`getEnclosingCallable` in DataFlow::Node:
```
/** Gets the enclosing callable of this node. */
DataFlowCallable getEnclosingCallable() { result = getCallableScope(this.getScope()) }
```
This commit is contained in:
@@ -467,7 +467,7 @@ class IterableSequenceNode extends Node, TIterableSequenceNode {
|
||||
|
||||
override string toString() { result = "IterableSequence" }
|
||||
|
||||
override DataFlowCallable getEnclosingCallable() { result = consumer.getEnclosingCallable() }
|
||||
override Scope getScope() { result = consumer.getScope() }
|
||||
|
||||
override Location getLocation() { result = consumer.getLocation() }
|
||||
}
|
||||
@@ -484,7 +484,7 @@ class IterableElementNode extends Node, TIterableElementNode {
|
||||
|
||||
override string toString() { result = "IterableElement" }
|
||||
|
||||
override DataFlowCallable getEnclosingCallable() { result = consumer.getEnclosingCallable() }
|
||||
override Scope getScope() { result = consumer.getScope() }
|
||||
|
||||
override Location getLocation() { result = consumer.getLocation() }
|
||||
}
|
||||
@@ -499,7 +499,7 @@ class StarPatternElementNode extends Node, TStarPatternElementNode {
|
||||
|
||||
override string toString() { result = "StarPatternElement" }
|
||||
|
||||
override DataFlowCallable getEnclosingCallable() { result = consumer.getEnclosingCallable() }
|
||||
override Scope getScope() { result = consumer.getScope() }
|
||||
|
||||
override Location getLocation() { result = consumer.getLocation() }
|
||||
}
|
||||
|
||||
@@ -3,5 +3,5 @@
|
||||
|
||||
t = (SOURCE, NONSOURCE)
|
||||
a, b = t
|
||||
SINK(a) #$ MISSING: flow="SOURCE, l:-2 -> a"
|
||||
SINK(a) #$ flow="SOURCE, l:-2 -> a"
|
||||
SINK_F(b)
|
||||
|
||||
Reference in New Issue
Block a user