Skip to content

Commit 1027ca2

Browse files
committed
JS: Allow many Array steps to be used in type-tracking
1 parent 06aa266 commit 1027ca2

File tree

1 file changed

+16
-16
lines changed

1 file changed

+16
-16
lines changed

javascript/ql/lib/semmle/javascript/Arrays.qll

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -115,9 +115,9 @@ private module ArrayDataFlow {
115115
* A step modeling the creation of an Array using the `Array.from(x)` method.
116116
* The step copies the elements of the argument (set, array, or iterator elements) into the resulting array.
117117
*/
118-
private class ArrayFrom extends DataFlow::SharedFlowStep {
118+
private class ArrayFrom extends PreCallGraphStep {
119119
override predicate loadStoreStep(
120-
DataFlow::Node pred, DataFlow::Node succ, string fromProp, string toProp
120+
DataFlow::Node pred, DataFlow::SourceNode succ, string fromProp, string toProp
121121
) {
122122
exists(DataFlow::CallNode call |
123123
call = arrayFromCall() and
@@ -135,9 +135,9 @@ private module ArrayDataFlow {
135135
*
136136
* Such a step can occur both with the `push` and `unshift` methods, or when creating a new array.
137137
*/
138-
private class ArrayCopySpread extends DataFlow::SharedFlowStep {
138+
private class ArrayCopySpread extends PreCallGraphStep {
139139
override predicate loadStoreStep(
140-
DataFlow::Node pred, DataFlow::Node succ, string fromProp, string toProp
140+
DataFlow::Node pred, DataFlow::SourceNode succ, string fromProp, string toProp
141141
) {
142142
fromProp = arrayLikeElement() and
143143
toProp = arrayElement() and
@@ -156,7 +156,7 @@ private module ArrayDataFlow {
156156
/**
157157
* A step for storing an element on an array using `arr.push(e)` or `arr.unshift(e)`.
158158
*/
159-
private class ArrayAppendStep extends DataFlow::SharedFlowStep {
159+
private class ArrayAppendStep extends PreCallGraphStep {
160160
override predicate storeStep(DataFlow::Node element, DataFlow::SourceNode obj, string prop) {
161161
prop = arrayElement() and
162162
exists(DataFlow::MethodCallNode call |
@@ -187,7 +187,7 @@ private module ArrayDataFlow {
187187
* A step for reading/writing an element from an array inside a for-loop.
188188
* E.g. a read from `foo[i]` to `bar` in `for(var i = 0; i < arr.length; i++) {bar = foo[i]}`.
189189
*/
190-
private class ArrayIndexingStep extends DataFlow::SharedFlowStep {
190+
private class ArrayIndexingStep extends PreCallGraphStep {
191191
override predicate loadStep(DataFlow::Node obj, DataFlow::Node element, string prop) {
192192
exists(ArrayIndexingAccess access |
193193
prop = arrayElement() and
@@ -209,7 +209,7 @@ private module ArrayDataFlow {
209209
* A step for retrieving an element from an array using `.pop()`, `.shift()`, or `.at()`.
210210
* E.g. `array.pop()`.
211211
*/
212-
private class ArrayPopStep extends DataFlow::SharedFlowStep {
212+
private class ArrayPopStep extends PreCallGraphStep {
213213
override predicate loadStep(DataFlow::Node obj, DataFlow::Node element, string prop) {
214214
exists(DataFlow::MethodCallNode call |
215215
call.getMethodName() = ["pop", "shift", "at"] and
@@ -276,7 +276,7 @@ private module ArrayDataFlow {
276276
* A step modeling that `splice` can insert elements into an array.
277277
* For example in `array.splice(i, del, e)`: if `e` is tainted, then so is `array
278278
*/
279-
private class ArraySpliceStep extends DataFlow::SharedFlowStep {
279+
private class ArraySpliceStep extends PreCallGraphStep {
280280
override predicate storeStep(DataFlow::Node element, DataFlow::SourceNode obj, string prop) {
281281
exists(DataFlow::MethodCallNode call |
282282
call.getMethodName() = "splice" and
@@ -291,8 +291,8 @@ private module ArrayDataFlow {
291291
* A step for modeling `concat`.
292292
* For example in `e = arr1.concat(arr2, arr3)`: if any of the `arr` is tainted, then so is `e`.
293293
*/
294-
private class ArrayConcatStep extends DataFlow::SharedFlowStep {
295-
override predicate loadStoreStep(DataFlow::Node pred, DataFlow::Node succ, string prop) {
294+
private class ArrayConcatStep extends PreCallGraphStep {
295+
override predicate loadStoreStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) {
296296
exists(DataFlow::MethodCallNode call |
297297
call.getMethodName() = "concat" and
298298
prop = arrayElement() and
@@ -305,8 +305,8 @@ private module ArrayDataFlow {
305305
/**
306306
* A step for modeling that elements from an array `arr` also appear in the result from calling `slice`/`splice`/`filter`.
307307
*/
308-
private class ArraySliceStep extends DataFlow::SharedFlowStep {
309-
override predicate loadStoreStep(DataFlow::Node pred, DataFlow::Node succ, string prop) {
308+
private class ArraySliceStep extends PreCallGraphStep {
309+
override predicate loadStoreStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) {
310310
exists(DataFlow::MethodCallNode call |
311311
call.getMethodName() = ["slice", "splice", "filter"] and
312312
prop = arrayElement() and
@@ -319,7 +319,7 @@ private module ArrayDataFlow {
319319
/**
320320
* A step modeling that elements from an array `arr` are received by calling `find`.
321321
*/
322-
private class ArrayFindStep extends DataFlow::SharedFlowStep {
322+
private class ArrayFindStep extends PreCallGraphStep {
323323
override predicate loadStep(DataFlow::Node pred, DataFlow::Node succ, string prop) {
324324
exists(DataFlow::CallNode call |
325325
call = arrayFindCall(pred) and
@@ -382,7 +382,7 @@ private module ArrayLibraries {
382382
* E.g. `array-union` that creates a union of multiple arrays, or `array-uniq` that creates an array with unique elements.
383383
*/
384384
DataFlow::CallNode arrayCopyCall(DataFlow::Node array) {
385-
result = API::moduleImport(["array-union", "array-uniq", "uniq"]).getACall() and
385+
result = DataFlow::moduleImport(["array-union", "array-uniq", "uniq"]).getACall() and
386386
array = result.getAnArgument()
387387
}
388388

@@ -401,8 +401,8 @@ private module ArrayLibraries {
401401
/**
402402
* A loadStoreStep for a library that copies the elements of an array into another array.
403403
*/
404-
private class ArrayCopyLoadStore extends DataFlow::SharedFlowStep {
405-
override predicate loadStoreStep(DataFlow::Node pred, DataFlow::Node succ, string prop) {
404+
private class ArrayCopyLoadStore extends PreCallGraphStep {
405+
override predicate loadStoreStep(DataFlow::Node pred, DataFlow::SourceNode succ, string prop) {
406406
exists(DataFlow::CallNode call |
407407
call = arrayCopyCall(pred) and
408408
succ = call and

0 commit comments

Comments
 (0)