Skip to content

Commit e870ee4

Browse files
committed
Python: Use AttrWrite.writes
Also applies @Napalys' fix to the base case.
1 parent 2a0431f commit e870ee4

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

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

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -574,16 +574,15 @@ predicate globalVariableNestedFieldJumpStep(Node nodeFrom, Node nodeTo) {
574574
) and
575575
write.getAttributeName() = read.getAttributeName() and
576576
nodeFrom = write.getValue() and
577-
nodeTo = read //and
578-
//write.getEnclosingCallable() != read.getEnclosingCallable()
577+
nodeTo = read
579578
)
580579
}
581580

582581
/**
583582
* Maximum depth for global variable nested attribute access.
584583
* Depth 0 = globalVar.foo, depth 1 = globalVar.foo.bar, depth 2 = globalVar.foo.bar.baz, etc.
585584
*/
586-
private int getMaxGlobalVariableDepth() { result = 10 }
585+
private int getMaxGlobalVariableDepth() { result = 2 }
587586

588587
/**
589588
* Holds if `node` is an attribute access path starting from global variable `globalVar`.
@@ -604,13 +603,15 @@ predicate globalVariableAttrPathAtDepth(
604603
) {
605604
// Base case: Direct global variable access (depth 0)
606605
depth = 0 and
607-
node in [globalVar.getARead(), globalVar.getAWrite(), globalVar] and
606+
// We use `globalVar` instead of `globalVar.getAWrite()` due to some weirdness with how
607+
// attribute writes are handled in the global scope (see `GlobalAttributeAssignmentAsAttrWrite`).
608+
node in [globalVar.getARead(), globalVar] and
608609
accessPath = ""
609610
or
610611
exists(Node obj, string attrName, string parentAccessPath, int parentDepth |
611-
node.(AttrRead).accesses(obj, attrName)
612+
node.(AttrRead).reads(obj, attrName)
612613
or
613-
exists(AttrWrite aw | aw.accesses(obj, attrName) and aw.getValue() = node)
614+
any(AttrWrite aw).writes(obj, attrName, node)
614615
|
615616
globalVariableAttrPathAtDepth(globalVar, parentAccessPath, obj, parentDepth) and
616617
accessPath = parentAccessPath + "." + attrName and

0 commit comments

Comments
 (0)