Skip to content

Commit 623ad6b

Browse files
committed
Python: Add getADefiningWrite
1 parent 79bae0c commit 623ad6b

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

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

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -335,11 +335,7 @@ predicate runtimeJumpStep(Node nodeFrom, Node nodeTo) {
335335
nodeFrom = nodeTo.(ModuleVariableNode).getAWrite()
336336
or
337337
// Setting the possible values of the variable at the end of import time
338-
exists(SsaVariable def |
339-
def = any(SsaVariable var).getAnUltimateDefinition() and
340-
def.getDefinition() = nodeFrom.asCfgNode() and
341-
def.getVariable() = nodeTo.(ModuleVariableNode).getVariable()
342-
)
338+
nodeFrom = nodeTo.(ModuleVariableNode).getADefiningWrite()
343339
}
344340

345341
/**

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -393,6 +393,15 @@ class ModuleVariableNode extends Node, TModuleVariableNode {
393393
result.asVar().getDefinition().(EssaNodeDefinition).definedBy(var, any(DefinitionNode defn))
394394
}
395395

396+
/** Gets the possible values of the variable at the end of import time */
397+
CfgNode getADefiningWrite() {
398+
exists(SsaVariable def |
399+
def = any(SsaVariable ssa_var).getAnUltimateDefinition() and
400+
def.getDefinition() = result.asCfgNode() and
401+
def.getVariable() = var
402+
)
403+
}
404+
396405
override DataFlowCallable getEnclosingCallable() { result.(DataFlowModuleScope).getScope() = mod }
397406

398407
override Location getLocation() { result = mod.getLocation() }

0 commit comments

Comments
 (0)