Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9fc99d6

Browse files
committed
JS: Fix store into object literals that have a post-update node
1 parent d626e79 commit 9fc99d6

2 files changed

Lines changed: 21 additions & 8 deletions

File tree

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,15 +1283,28 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
12831283
}
12841284

12851285
/** Gets the post-update node for which `node` is the corresponding pre-update node. */
1286-
private Node getPostUpdate(Node node) { result.(PostUpdateNode).getPreUpdateNode() = node }
1286+
private Node getPostUpdateForStore(Node base) {
1287+
// Some nodes have post-update nodes but should not be targeted by a PropWrite store.
1288+
// Notably, an object literal can have a post-update node it if is an argument to a call,
1289+
// but in this case, we should not target the post-update node, as this would prevent data from
1290+
// flowing into the call.
1291+
exists(Expr expr |
1292+
base = TValueNode(expr) and
1293+
result = TExprPostUpdateNode(expr)
1294+
|
1295+
expr instanceof PropAccess or
1296+
expr instanceof VarAccess or
1297+
expr instanceof ThisExpr
1298+
)
1299+
}
12871300

1288-
/** Gets the post-update node for which node is the pre-update node, if one exists, otherwise gets `node` itself. */
1301+
/** Gets node to target with a store to the given `base` object.. */
12891302
pragma[inline]
1290-
private Node tryGetPostUpdate(Node node) {
1291-
result = getPostUpdate(node)
1303+
private Node getStoreTarget(Node base) {
1304+
result = getPostUpdateForStore(base)
12921305
or
1293-
not exists(getPostUpdate(node)) and
1294-
result = node
1306+
not exists(getPostUpdateForStore(base)) and
1307+
result = base
12951308
}
12961309

12971310
pragma[nomagic]
@@ -1309,7 +1322,7 @@ predicate storeStep(Node node1, ContentSet c, Node node2) {
13091322
node1 = write.getRhs() and
13101323
c.asPropertyName() = write.getPropertyName() and
13111324
// Target the post-update node if one exists (for object literals we do not generate post-update nodes)
1312-
node2 = tryGetPostUpdate(write.getBase())
1325+
node2 = getStoreTarget(write.getBase())
13131326
)
13141327
or
13151328
FlowSummaryPrivate::Steps::summaryStoreStep(node1.(FlowSummaryNode).getSummaryNode(), c,

javascript/ql/test/library-tests/TripleDot/useuse.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function t2() {
3131

3232
function t3() {
3333
function inner(obj) {
34-
sink(obj.foo); // $ hasValueFlow=t3.2 MISSING: hasValueFlow=t3.1
34+
sink(obj.foo); // $ hasValueFlow=t3.2 hasValueFlow=t3.1
3535
}
3636

3737
inner({foo: source('t3.1')});

0 commit comments

Comments
 (0)