Skip to content

Commit 7cf88ef

Browse files
committed
JS: Add global post-update steps
1 parent afcd15e commit 7cf88ef

File tree

2 files changed

+25
-0
lines changed

2 files changed

+25
-0
lines changed

javascript/ql/lib/semmle/javascript/dataflow/internal/DataFlowPrivate.qll

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -671,6 +671,8 @@ private predicate valuePreservingStep(Node node1, Node node2) {
671671
or
672672
FlowSteps::globalFlowStep(node1, node2)
673673
or
674+
FlowSteps::globalPostUpdateStep(node1, node2)
675+
or
674676
node2 = FlowSteps::getThrowTarget(node1)
675677
or
676678
FlowSummaryImpl::Private::Steps::summaryLocalStep(node1.(FlowSummaryNode).getSummaryNode(),

javascript/ql/lib/semmle/javascript/dataflow/internal/FlowSteps.qll

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -383,6 +383,14 @@ private module CachedSteps {
383383
result = DataFlow::valueNode(gv.getAnAccess())
384384
}
385385

386+
/**
387+
* Gets a post-update of `gv` in `f`.
388+
*/
389+
pragma[noinline]
390+
private DataFlow::ExprPostUpdateNode getAPostUpdateIn(GlobalVariable gv, File f) {
391+
result.getPreUpdateNode() = getAUseIn(gv, f)
392+
}
393+
386394
/**
387395
* Holds if there is a flow step from `pred` to `succ` through a global
388396
* variable. Both `pred` and `succ` must be in the same file.
@@ -395,6 +403,20 @@ private module CachedSteps {
395403
)
396404
}
397405

406+
/**
407+
* Holds if `pred` is a post-update node for a use of a global variable, and `succ`
408+
* is a use of the global variable in the same file.
409+
*/
410+
cached
411+
predicate globalPostUpdateStep(DataFlow::Node pred, DataFlow::Node succ) {
412+
exists(GlobalVariable gv, File f |
413+
pred = getAPostUpdateIn(gv, f) and
414+
succ = getAUseIn(gv, f) and
415+
// Remove some unnecessary steps
416+
not succ = any(DataFlow::PropWrite write).getBase()
417+
)
418+
}
419+
398420
/**
399421
* Holds if there is a write to property `prop` of global variable `gv`
400422
* in file `f`, where the right-hand side of the write is `rhs`.
@@ -438,6 +460,7 @@ private module CachedSteps {
438460
predicate basicStoreStep(DataFlow::Node pred, DataFlow::Node succ, string prop) {
439461
succ.(DataFlow::SourceNode).hasPropertyWrite(prop, pred)
440462
or
463+
// Note that this case is handled by globalPostUpdateStep in dataflow2
441464
exists(GlobalVariable gv, File f |
442465
globalPropertyWrite(gv, f, prop, pred) and
443466
globalPropertyRead(gv, f, prop, succ)

0 commit comments

Comments
 (0)