Skip to content

Commit badf631

Browse files
authored
Python: Remove flow between globals...
... in a local scope. Or rather, remove these from the `hasLocalSource` relation. This prevents a quadratic blowup when the same global is mentioned _a lot_ of times within a single function scope.
1 parent ed794f4 commit badf631

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

python/ql/src/semmle/python/dataflow/new/internal/LocalSources.qll

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -179,11 +179,21 @@ private module Cached {
179179
source = sink
180180
or
181181
exists(Node second |
182-
simpleLocalFlowStep(source, second) and
183-
simpleLocalFlowStep*(second, sink)
182+
localSourceFlowStep(source, second) and
183+
localSourceFlowStep*(second, sink)
184184
)
185185
}
186186

187+
/**
188+
* Helper predicate for `hasLocalSource`. Removes any steps go to module variable reads, as these
189+
* are already local source nodes in their own right.
190+
*/
191+
cached
192+
private predicate localSourceFlowStep(Node nodeFrom, Node nodeTo) {
193+
simpleLocalFlowStep(nodeFrom, nodeTo) and
194+
not nodeTo = any(ModuleVariableNode v).getARead()
195+
}
196+
187197
/**
188198
* Holds if `base` flows to the base of `ref` and `ref` has attribute name `attr`.
189199
*/

0 commit comments

Comments
 (0)