|
| 1 | +private import javascript |
| 2 | +private import semmle.javascript.dataflow.FlowSummary |
| 3 | +private import semmle.javascript.dataflow.InferredTypes |
| 4 | +private import semmle.javascript.dataflow.internal.DataFlowPrivate as Private |
| 5 | +private import FlowSummaryUtil |
| 6 | + |
| 7 | +private class TypedArrayEntryPoint extends API::EntryPoint { |
| 8 | + TypedArrayEntryPoint() { this = "global.Uint8Array" } |
| 9 | + |
| 10 | + override DataFlow::SourceNode getASource() { result = DataFlow::globalVarRef("Uint8Array") } |
| 11 | +} |
| 12 | + |
| 13 | +pragma[nomagic] |
| 14 | +API::Node typedArrayConstructorRef() { result = any(TypedArrayEntryPoint e).getANode() } |
| 15 | + |
| 16 | +class TypedArrayConstructorSummary extends SummarizedCallable { |
| 17 | + TypedArrayConstructorSummary() { this = "TypedArray constructor" } |
| 18 | + |
| 19 | + override DataFlow::InvokeNode getACall() { |
| 20 | + result = typedArrayConstructorRef().getAnInstantiation() |
| 21 | + } |
| 22 | + |
| 23 | + override predicate propagatesFlow(string input, string output, boolean preservesValue) { |
| 24 | + preservesValue = true and |
| 25 | + input = "Argument[0].ArrayElement" and |
| 26 | + output = "ReturnValue.ArrayElement" |
| 27 | + } |
| 28 | +} |
| 29 | + |
| 30 | +class BufferTypedArray extends DataFlow::AdditionalFlowStep { |
| 31 | + override predicate step(DataFlow::Node pred, DataFlow::Node succ) { |
| 32 | + exists(DataFlow::PropRead p | |
| 33 | + p = typedArrayConstructorRef().getInstance().getMember("buffer").asSource() and |
| 34 | + pred = p.getBase() and |
| 35 | + succ = p |
| 36 | + ) |
| 37 | + } |
| 38 | +} |
| 39 | + |
| 40 | +class TypedArraySet extends SummarizedCallable { |
| 41 | + TypedArraySet() { this = "TypedArray#set" } |
| 42 | + |
| 43 | + override InstanceCall getACall() { |
| 44 | + result = typedArrayConstructorRef().getInstance().getMember("set").getACall() |
| 45 | + } |
| 46 | + |
| 47 | + override predicate propagatesFlow(string input, string output, boolean preservesValue) { |
| 48 | + preservesValue = true and |
| 49 | + input = "Argument[0].ArrayElement" and |
| 50 | + output = "Argument[this].ArrayElement" |
| 51 | + } |
| 52 | +} |
| 53 | + |
| 54 | +class TypedArraySubarray extends SummarizedCallable { |
| 55 | + TypedArraySubarray() { this = "TypedArray#subarray" } |
| 56 | + |
| 57 | + override InstanceCall getACall() { result.getMethodName() = "subarray" } |
| 58 | + |
| 59 | + override predicate propagatesFlow(string input, string output, boolean preservesValue) { |
| 60 | + preservesValue = true and |
| 61 | + input = "Argument[this].ArrayElement" and |
| 62 | + output = "ReturnValue.ArrayElement" |
| 63 | + } |
| 64 | +} |
| 65 | + |
| 66 | +private class ArrayBufferEntryPoint extends API::EntryPoint { |
| 67 | + ArrayBufferEntryPoint() { this = ["global.ArrayBuffer", "global.SharedArrayBuffer"] } |
| 68 | + |
| 69 | + override DataFlow::SourceNode getASource() { |
| 70 | + result = DataFlow::globalVarRef(["ArrayBuffer", "SharedArrayBuffer"]) |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +pragma[nomagic] |
| 75 | +API::Node arrayBufferConstructorRef() { result = any(ArrayBufferEntryPoint a).getANode() } |
| 76 | + |
| 77 | +class TransferLike extends SummarizedCallable { |
| 78 | + TransferLike() { this = "ArrayBuffer#transfer" } |
| 79 | + |
| 80 | + override InstanceCall getACall() { |
| 81 | + result.getMethodName() = ["transfer", "transferToFixedLength"] |
| 82 | + } |
| 83 | + |
| 84 | + override predicate propagatesFlow(string input, string output, boolean preservesValue) { |
| 85 | + preservesValue = true and |
| 86 | + input = "Argument[this].ArrayElement" and |
| 87 | + output = "ReturnValue.ArrayElement" |
| 88 | + } |
| 89 | +} |
0 commit comments