Skip to content

Commit a9062cc

Browse files
committed
merge hasDominatingWrite and hasDominatingAssignment
1 parent 169f655 commit a9062cc

File tree

2 files changed

+16
-10
lines changed

2 files changed

+16
-10
lines changed

javascript/ql/lib/semmle/javascript/DynamicPropertyAccess.qll

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -181,16 +181,7 @@ class DynamicPropRead extends DataFlow::SourceNode, DataFlow::ValueNode {
181181
* dst[x][y] = src[y];
182182
* ```
183183
*/
184-
predicate hasDominatingAssignment() {
185-
exists(DataFlow::PropWrite write, BasicBlock bb, int i, int j, SsaVariable ssaVar |
186-
write = getBase().getALocalSource().getAPropertyWrite() and
187-
bb.getNode(i) = write.getWriteNode() and
188-
bb.getNode(j) = astNode and
189-
i < j and
190-
write.getPropertyNameExpr() = ssaVar.getAUse() and
191-
astNode.getIndex() = ssaVar.getAUse()
192-
)
193-
}
184+
predicate hasDominatingAssignment() { AccessPath::DominatingPaths::hasDominatingWrite(this) }
194185
}
195186

196187
/**

javascript/ql/lib/semmle/javascript/GlobalAccessPaths.qll

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,21 @@ module AccessPath {
569569
read.asExpr() = getAccessTo(root, path, AccessPathRead()) and
570570
getAWriteBlock(root, path).strictlyDominates(read.getBasicBlock())
571571
)
572+
or
573+
// Dynamic write where the same variable is used to index the read and write (in the same basic block)
574+
// For example, this is true for `dst[x]` on line 2 below:
575+
// ```js
576+
// dst[x] = {};
577+
// dst[x][y] = src[y];
578+
// ```
579+
exists(DataFlow::PropWrite write, BasicBlock bb, int i, int j, SsaVariable ssaVar |
580+
write = read.getBase().getALocalSource().getAPropertyWrite() and
581+
bb.getNode(i) = write.getWriteNode() and
582+
bb.getNode(j) = read.asExpr() and
583+
i < j and
584+
write.getPropertyNameExpr() = ssaVar.getAUse() and
585+
read.getPropertyNameExpr() = ssaVar.getAUse()
586+
)
572587
}
573588
}
574589
}

0 commit comments

Comments
 (0)