Skip to content

Commit dd3342b

Browse files
committed
restrict the number of stored array elements
1 parent 4eb9684 commit dd3342b

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

javascript/ql/src/semmle/javascript/Arrays.qll

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -253,14 +253,10 @@ private module ArrayDataFlow {
253253
*/
254254
private class ArrayCreationStep extends DataFlow::AdditionalFlowStep, DataFlow::ArrayCreationNode {
255255
override predicate storeStep(DataFlow::Node element, DataFlow::SourceNode obj, string prop) {
256-
prop = arrayElement() and
257-
element = this.getAnElement() and
258-
obj = this
259-
or
260256
exists(int i |
261257
element = this.getElement(i) and
262258
obj = this and
263-
prop = i.toString()
259+
prop = arrayElement(i)
264260
)
265261
}
266262
}

javascript/ql/src/semmle/javascript/dataflow/Configuration.qll

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,16 @@ module PseudoProperties {
607607
*/
608608
string arrayElement() { result = pseudoProperty("arrayElement") }
609609

610+
/**
611+
* Gets a pseudo-property for the location of the `i`th element in an `Array`.
612+
*/
613+
bindingset[i]
614+
string arrayElement(int i) {
615+
i < 5 and result = i.toString()
616+
or
617+
result = arrayElement()
618+
}
619+
610620
/**
611621
* Gets a pseudo-property for the location of elements in some array-like object. (Set, Array, or Iterator).
612622
*/

0 commit comments

Comments
 (0)