Skip to content

Commit efcdb3e

Browse files
committed
Python: filter local flow from a node to itself
1 parent 5471c92 commit efcdb3e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,8 +684,13 @@ predicate summaryFlowSteps(Node nodeFrom, Node nodeTo) {
684684
}
685685

686686
predicate variableCaptureFlowStep(Node nodeFrom, Node nodeTo) {
687+
// Blindly applying use-use flow can result in a node that steps to itself, for
688+
// example in while-loops. To uphold dataflow consistency checks, we don't want
689+
// that. However, we do want to allow `[post] n` to `n` (to handle while loops), so
690+
// we should only do the filtering after `IncludePostUpdateFlow` has ben applied.
687691
IncludePostUpdateFlow<PhaseDependentFlow<VariableCapture::valueStep/2>::step/2>::step(nodeFrom,
688-
nodeTo)
692+
nodeTo) and
693+
nodeFrom != nodeTo
689694
}
690695

691696
/** `ModuleVariable`s are accessed via jump steps at runtime. */

0 commit comments

Comments
 (0)