Skip to content

Commit f427720

Browse files
committed
Add flow summaries and entry points for ArrayBuffer and SharedArrayBuffer
1 parent 0e09947 commit f427720

File tree

2 files changed

+52
-4
lines changed

2 files changed

+52
-4
lines changed

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,3 +65,47 @@ class SubArrayLike extends SummarizedCallable {
6565
output = "ReturnValue.ArrayElement"
6666
}
6767
}
68+
69+
private class ArrayBufferEntryPoint extends API::EntryPoint {
70+
ArrayBufferEntryPoint() { this = ["global.ArrayBuffer", "global.SharedArrayBuffer"] }
71+
72+
override DataFlow::SourceNode getASource() {
73+
result = DataFlow::globalVarRef(["ArrayBuffer", "SharedArrayBuffer"])
74+
}
75+
}
76+
77+
pragma[nomagic]
78+
API::Node arrayBufferConstructorRef() { result = any(ArrayBufferEntryPoint a).getANode() }
79+
80+
class ArrayBufferConstructorSummary extends SummarizedCallable {
81+
ArrayBufferConstructorSummary() { this = "ArrayBuffer constructor" }
82+
83+
override DataFlow::InvokeNode getACall() {
84+
result = arrayBufferConstructorRef().getAnInstantiation()
85+
}
86+
87+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
88+
preservesValue = true and
89+
input = "Argument[0].ArrayElement" and
90+
output = "ReturnValue.ArrayElement"
91+
}
92+
}
93+
94+
class TransferLike extends SummarizedCallable {
95+
TransferLike() { this = "ArrayBuffer#transfer" }
96+
97+
override InstanceCall getACall() {
98+
result =
99+
arrayBufferConstructorRef()
100+
.getAnInstantiation()
101+
.getReturn()
102+
.getMember(["transfer", "transferToFixedLength"])
103+
.getACall()
104+
}
105+
106+
override predicate propagatesFlow(string input, string output, boolean preservesValue) {
107+
preservesValue = true and
108+
input = "Argument[this].ArrayElement" and
109+
output = "ReturnValue.ArrayElement"
110+
}
111+
}

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -40,15 +40,15 @@ legacyDataFlowDifference
4040
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:11:10:11:12 | arr | only flow with NEW data flow library |
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 |
43+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:22:10:22:13 | view | only flow with NEW data flow library |
44+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:26:10:26:14 | view1 | only flow with NEW data flow library |
45+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:30:10:30:23 | transferedView | only flow with NEW data flow library |
46+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:34:10:34:24 | transferedView2 | only flow with NEW data flow library |
4347
| 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 |
4448
consistencyIssue
4549
| nested-props.js:20 | expected an alert, but found none | NOT OK - but not found | Consistency |
4650
| stringification-read-steps.js:17 | expected an alert, but found none | NOT OK | Consistency |
4751
| stringification-read-steps.js:25 | expected an alert, but found none | NOT OK | Consistency |
48-
| typed-arrays.js:22 | 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 |
5252
flow
5353
| access-path-sanitizer.js:2:18:2:25 | source() | access-path-sanitizer.js:4:8:4:12 | obj.x |
5454
| addexpr.js:4:10:4:17 | source() | addexpr.js:7:8:7:8 | x |
@@ -339,6 +339,10 @@ flow
339339
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:11:10:11:12 | arr |
340340
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:15:10:15:10 | z |
341341
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:18:10:18:12 | sub |
342+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:22:10:22:13 | view |
343+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:26:10:26:14 | view1 |
344+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:30:10:30:23 | transferedView |
345+
| typed-arrays.js:2:13:2:20 | source() | typed-arrays.js:34:10:34:24 | transferedView2 |
342346
| use-use-after-implicit-read.js:7:17:7:24 | source() | use-use-after-implicit-read.js:8:10:8:17 | captured |
343347
| use-use-after-implicit-read.js:7:17:7:24 | source() | use-use-after-implicit-read.js:15:10:15:10 | x |
344348
| xml.js:5:18:5:25 | source() | xml.js:8:14:8:17 | text |

0 commit comments

Comments
 (0)