Skip to content

Commit 832d6fb

Browse files
committed
Prepare LocalSourceNode for locality
Removes the dependence on the (global) `ModuleVariableNode.getARead()`, by adding a local version (that doesn't include `import *` reads) instead.
1 parent 636bbe3 commit 832d6fb

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPublic.qll

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -440,13 +440,17 @@ class ModuleVariableNode extends Node, TModuleVariableNode {
440440

441441
/** Gets a node that reads this variable. */
442442
Node getARead() {
443-
result.asCfgNode() = var.getALoad().getAFlowNode() and
444-
// Ignore reads that happen when the module is imported. These are only executed once.
445-
not result.getScope() = mod
443+
result = this.getALocalRead()
446444
or
447445
this = import_star_read(result)
448446
}
449447

448+
/** Gets a node that reads this variable, excluding reads that happen through `from ... import *`. */
449+
Node getALocalRead() {
450+
result.asCfgNode() = var.getALoad().getAFlowNode() and
451+
not result.getScope() = mod
452+
}
453+
450454
/** Gets an `EssaNode` that corresponds to an assignment of this global variable. */
451455
Node getAWrite() {
452456
any(EssaNodeDefinition def).definedBy(var, result.asCfgNode().(DefinitionNode))

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class LocalSourceNode extends Node {
6767
or
6868
// We explicitly include any read of a global variable, as some of these may have local flow going
6969
// into them.
70-
this = any(ModuleVariableNode mvn).getARead()
70+
this = any(ModuleVariableNode v).getALocalRead()
7171
or
7272
// We include all scope entry definitions, as these act as the local source within the scope they
7373
// enter.
@@ -248,7 +248,7 @@ private module Cached {
248248
pragma[nomagic]
249249
private predicate localSourceFlowStep(Node nodeFrom, Node nodeTo) {
250250
simpleLocalFlowStep(nodeFrom, nodeTo, _) and
251-
not nodeTo = any(ModuleVariableNode v).getARead()
251+
not nodeTo = any(ModuleVariableNode v).getALocalRead()
252252
}
253253

254254
/**

0 commit comments

Comments
 (0)