Skip to content

Commit 76e3c54

Browse files
committed
Add flow summaries and entry points for ArrayBuffer and SharedArrayBuffer
1 parent 8dc5519 commit 76e3c54

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

javascript/ql/lib/semmle/javascript/internal/flow_summaries/TypedArrays.qll

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,3 +60,42 @@ class SubArrayLike extends SummarizedCallable {
6060
output = "ReturnValue.ArrayElement"
6161
}
6262
}
63+
64+
private class ArrayBufferEntryPoint extends API::EntryPoint {
65+
ArrayBufferEntryPoint() { this = ["global.ArrayBuffer", "global.SharedArrayBuffer"] }
66+
67+
override DataFlow::SourceNode getASource() {
68+
result = DataFlow::globalVarRef(["ArrayBuffer", "SharedArrayBuffer"])
69+
}
70+
}
71+
72+
pragma[nomagic]
73+
API::Node arrayBufferConstructorRef() { result = any(ArrayBufferEntryPoint a).getANode() }
74+
75+
class ArrayBufferConstructorSummary extends SummarizedCallable {
76+
ArrayBufferConstructorSummary() { this = "ArrayBuffer constructor" }
77+
78+
override DataFlow::InvokeNode getACall() {
79+
result = arrayBufferConstructorRef().getAnInstantiation()
80+
}
81+
82+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
83+
preservesValue = true and
84+
input = "Argument[0].ArrayElement" and
85+
output = "ReturnValue.ArrayElement"
86+
}
87+
}
88+
89+
class TransferLike extends SummarizedCallable {
90+
TransferLike() { this = "ArrayBuffer#transfer" }
91+
92+
override InstanceCall getACall() {
93+
result.getMethodName() = ["transfer", "transferToFixedLength"]
94+
}
95+
96+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
97+
preservesValue = true and
98+
input = "Argument[this].ArrayElement" and
99+
output = "ReturnValue.ArrayElement"
100+
}
101+
}

javascript/ql/test/library-tests/TaintTracking/BasicTaintTracking.expected

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ legacyDataFlowDifference
4141
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:15:10:15:10 | z | only flow with NEW data flow library |
4242
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:18:10:18:12 | sub | only flow with NEW data flow library |
4343
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:22:10:22:14 | clone | only flow with NEW data flow library |
44+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:26:10:26:13 | view | only flow with NEW data flow library |
45+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:30:10:30:14 | view1 | only flow with NEW data flow library |
46+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:34:10:34:23 | transferedView | only flow with NEW data flow library |
47+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:38:10:38:24 | transferedView2 | only flow with NEW data flow library |
4448
| use-use-after-implicit-read.js:7:17:7:24 | source() | use-use-after-implicit-read.js:15:10:15:10 | x | only flow with NEW data flow library |
4549
consistencyIssue
4650
| nested-props.js:20 | expected an alert, but found none | NOT OK - but not found | Consistency |
4751
| stringification-read-steps.js:17 | expected an alert, but found none | NOT OK | Consistency |
4852
| stringification-read-steps.js:25 | expected an alert, but found none | NOT OK | Consistency |
49-
| typed-arrays.js:26 | expected an alert, but found none | NOT OK | Consistency |
50-
| typed-arrays.js:30 | expected an alert, but found none | NOT OK | Consistency |
51-
| typed-arrays.js:34 | expected an alert, but found none | NOT OK | Consistency |
52-
| typed-arrays.js:38 | expected an alert, but found none | NOT OK | Consistency |
5353
flow
5454
| access-path-sanitizer.js:2:18:2:25 | source() | access-path-sanitizer.js:4:8:4:12 | obj.x |
5555
| addexpr.js:4:10:4:17 | source() | addexpr.js:7:8:7:8 | x |
@@ -341,6 +341,10 @@ flow
341341
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:15:10:15:10 | z |
342342
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:18:10:18:12 | sub |
343343
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:22:10:22:14 | clone |
344+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:26:10:26:13 | view |
345+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:30:10:30:14 | view1 |
346+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:34:10:34:23 | transferedView |
347+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:38:10:38:24 | transferedView2 |
344348
| use-use-after-implicit-read.js:7:17:7:24 | source() | use-use-after-implicit-read.js:8:10:8:17 | captured |
345349
| use-use-after-implicit-read.js:7:17:7:24 | source() | use-use-after-implicit-read.js:15:10:15:10 | x |
346350
| xml.js:5:18:5:25 | source() | xml.js:8:14:8:17 | text |

0 commit comments

Comments
 (0)