Skip to content

Commit c5e8e23

Browse files
committed
Python: Fix dataflow consistencies for default parameter values
1 parent 6f3cb67 commit c5e8e23

File tree

1 file changed

+13
-1
lines changed

1 file changed

+13
-1
lines changed

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -292,7 +292,12 @@ module EssaFlow {
292292
// nodeFrom is `f(42)`, cfg node
293293
// nodeTo is `x`, essa var
294294
nodeFrom.(CfgNode).getNode() =
295-
nodeTo.(EssaNode).getVar().getDefinition().(AssignmentDefinition).getValue()
295+
nodeTo.(EssaNode).getVar().getDefinition().(AssignmentDefinition).getValue() and
296+
// we need to ensure that enclosing callable is the same, since a parameter with a
297+
// default value will be in the scope of the function, while the default value
298+
// itself will be in the scope that _defines_ the function.
299+
// We handle _that_ as a jumpstep
300+
nodeFrom.getEnclosingCallable() = nodeTo.getEnclosingCallable()
296301
or
297302
// With definition
298303
// `with f(42) as x:`
@@ -463,6 +468,13 @@ predicate runtimeJumpStep(Node nodeFrom, Node nodeTo) {
463468
or
464469
// Setting the possible values of the variable at the end of import time
465470
nodeFrom = nodeTo.(ModuleVariableNode).getADefiningWrite()
471+
or
472+
// a parameter with a default value, since the parameter will be in the scope of the
473+
// function, while the default value itself will be in the scope that _defines_ the
474+
// function.
475+
nodeFrom.(CfgNode).getNode() =
476+
nodeTo.(EssaNode).getVar().getDefinition().(AssignmentDefinition).getValue() and
477+
not nodeFrom.getEnclosingCallable() = nodeTo.getEnclosingCallable()
466478
}
467479

468480
/**

0 commit comments

Comments
 (0)