Skip to content

Commit 4ad5118

Browse files
committed
Prepare LocalSourceNode for locality
Removes the dependence on the (global) `ModuleVariableNode.getARead()`. In the charpred we simply inline it. In `localSourceFlowStep` we discard any step _into_ a local source node.
1 parent 636bbe3 commit 4ad5118

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
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: 1 addition & 1 deletion
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.

0 commit comments

Comments
 (0)