Skip to content

Commit a9a8351

Browse files
committed
JS: Fix one case of missing handling of unknown array index
1 parent 379c7ef commit a9a8351

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1173,7 +1173,11 @@ predicate readStep(Node node1, ContentSet c, Node node2) {
11731173
then
11741174
c = ContentSet::arrayElement() and // unknown start index when not the first spread operator
11751175
storeContent.isUnknownArrayElement()
1176-
else storeContent.asArrayIndex() = n + c.asArrayIndex()
1176+
else (
1177+
storeContent.asArrayIndex() = n + c.asArrayIndex()
1178+
or
1179+
storeContent.isUnknownArrayElement() and c.asSingleton() = storeContent
1180+
)
11771181
)
11781182
or
11791183
exists(FlowSummaryNode parameter, ParameterPosition pos |

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,10 +153,10 @@ function t14() {
153153

154154
function t15() {
155155
function target(safe, x, y, ...rest) {
156-
sink(safe); // $ SPURIOUS: hasTaintFlow=t15.1
157-
sink(x); // $ MISSING: hasValueFlow=t15.1 SPURIOUS: hasTaintFlow=t15.1
158-
sink(y); // $ MISSING: hasValueFlow=t15.1 SPURIOUS: hasTaintFlow=t15.1
159-
sink(rest.pop()); // $ MISSING: hasValueFlow=t15.1 SPURIOUS: hasTaintFlow=t15.1
156+
sink(safe); // $ SPURIOUS: hasValueFlow=t15.1
157+
sink(x); // $ hasValueFlow=t15.1
158+
sink(y); // $ hasValueFlow=t15.1
159+
sink(rest.pop()); // $ hasValueFlow=t15.1
160160
sink(rest); // $ hasTaintFlow=t15.1
161161
}
162162
const args = new Array(Math.floor(Math.random() * 10));

0 commit comments

Comments
 (0)