diff options
author | Anna Henningsen <anna@addaleax.net> | 2019-01-30 14:57:24 +0100 |
---|---|---|
committer | Anna Henningsen <anna@addaleax.net> | 2019-02-01 16:09:22 +0100 |
commit | 0ff0af534ef150820ac218b6ef3614dc199de823 (patch) | |
tree | 09f3d164541ee063f5112a6d3642d633f99e7acb /src/node_messaging.cc | |
parent | 7c8ac5a01b4ba5d4c7060875ea024e6efbc12893 (diff) | |
download | android-node-v8-0ff0af534ef150820ac218b6ef3614dc199de823.tar.gz android-node-v8-0ff0af534ef150820ac218b6ef3614dc199de823.tar.bz2 android-node-v8-0ff0af534ef150820ac218b6ef3614dc199de823.zip |
worker: throw for duplicates in transfer list
Throw a `DataCloneError` exception when encountering duplicate
`ArrayBuffer`s or `MessagePort`s in the transfer list.
Fixes: https://github.com/nodejs/node/issues/25786
PR-URL: https://github.com/nodejs/node/pull/25815
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Diffstat (limited to 'src/node_messaging.cc')
-rw-r--r-- | src/node_messaging.cc | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/node_messaging.cc b/src/node_messaging.cc index aa4b92bf74..6e8e3e8ad7 100644 --- a/src/node_messaging.cc +++ b/src/node_messaging.cc @@ -289,6 +289,15 @@ Maybe<bool> Message::Serialize(Environment* env, // take ownership of its memory, copying the buffer will have to do. if (!ab->IsNeuterable() || ab->IsExternal()) continue; + if (std::find(array_buffers.begin(), array_buffers.end(), ab) != + array_buffers.end()) { + ThrowDataCloneException( + env, + FIXED_ONE_BYTE_STRING( + env->isolate(), + "Transfer list contains duplicate ArrayBuffer")); + return Nothing<bool>(); + } // We simply use the array index in the `array_buffers` list as the // ID that we write into the serialized buffer. uint32_t id = array_buffers.size(); @@ -314,6 +323,15 @@ Maybe<bool> Message::Serialize(Environment* env, "MessagePort in transfer list is already detached")); return Nothing<bool>(); } + if (std::find(delegate.ports_.begin(), delegate.ports_.end(), port) != + delegate.ports_.end()) { + ThrowDataCloneException( + env, + FIXED_ONE_BYTE_STRING( + env->isolate(), + "Transfer list contains duplicate MessagePort")); + return Nothing<bool>(); + } delegate.ports_.push_back(port); continue; } @@ -601,6 +619,7 @@ void MessagePort::OnClose() { } std::unique_ptr<MessagePortData> MessagePort::Detach() { + CHECK(data_); Mutex::ScopedLock lock(data_->mutex_); data_->owner_ = nullptr; return std::move(data_); |