Skip to content

Commit a9c1d3b

Browse files
authored
Python: Clean up LocalSourceNode charpred
This results in the same set of nodes, but is a bit more clear about the reasons why. For instance, `ModuleVariableNode`s are included directly, and not in a roundabout way by virtue of not having flow to them. This should hopefully be a bit more robust as well.
1 parent 336c066 commit a9c1d3b

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

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

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,15 @@ private import DataFlowPrivate
3333
class LocalSourceNode extends Node {
3434
cached
3535
LocalSourceNode() {
36-
not simpleLocalFlowStep(_, this) and
37-
// Currently, we create synthetic post-update nodes for
38-
// - arguments to calls that may modify said argument
39-
// - direct reads a writes of object attributes
40-
// Both of these preserve the identity of the underlying pointer, and hence we exclude these as
41-
// local source nodes.
42-
// We do, however, allow the post-update nodes that arise from object creation (which are non-synthetic).
43-
not this instanceof SyntheticPostUpdateNode and
44-
// With similar reasoning to the above, we also exclude the following synthesized nodes
45-
not this instanceof SyntheticPreUpdateNode and
46-
not this instanceof KwOverflowNode and
47-
not this instanceof PosOverflowNode and
48-
not this instanceof KwUnpackedNode and
49-
not this instanceof IterableSequenceNode and
50-
not this instanceof IterableElementNode and
51-
// ESSA nodes are also superfluous
52-
not this instanceof EssaNode
36+
this instanceof ExprNode and
37+
not simpleLocalFlowStep(_, this)
5338
or
39+
// Module variable nodes must be local source nodes, otherwise type trackers cannot step through
40+
// them.
41+
this instanceof ModuleVariableNode
42+
or
43+
// We explicitly include any read of a global variable, as some of these may have local flow going
44+
// into them.
5445
this = any(ModuleVariableNode mvn).getARead()
5546
}
5647

0 commit comments

Comments
 (0)