Skip to content

Commit

Permalink
Fix a data race in WebMessagePortChannelImpl.
Browse files Browse the repository at this point in the history
It's unsafe to pass a WebString (which is logically a RefPtr<StringImpl>)
across threads because the underlying object is not thread-safe ref-counted.
Instead, the base::string16 that the receiving method accepts should be
constructed before posting the task.

BUG=635659

Review-Url: https://codereview.chromium.org/2224393002
Cr-Commit-Position: refs/heads/master@{#410761}
  • Loading branch information
jeremyroman authored and Commit bot committed Aug 9, 2016
1 parent ec291e2 commit 414c42a
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion content/child/webmessageportchannel_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,13 @@ void WebMessagePortChannelImpl::postMessage(
WebMessagePortChannelArray* channels_ptr) {
std::unique_ptr<WebMessagePortChannelArray> channels(channels_ptr);
if (!main_thread_task_runner_->BelongsToCurrentThread()) {
// Note: we must construct the base::string16 here and pass that. Otherwise,
// the WebString will be passed, leading to references to the StringImpl
// from two threads, which is a data race.
main_thread_task_runner_->PostTask(
FROM_HERE, base::Bind(&WebMessagePortChannelImpl::SendPostMessage, this,
message, base::Passed(std::move(channels))));
base::Passed(base::string16(message)),
base::Passed(std::move(channels))));
} else {
SendPostMessage(message, std::move(channels));
}
Expand Down

0 comments on commit 414c42a

Please sign in to comment.