Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(20)

Side by Side Diff: blimp/engine/mojo/blob_channel_service.cc

Issue 2517733002: Throw IPC errors on invalid Mojo BlobChannel messages. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "blimp/engine/mojo/blob_channel_service.h" 5 #include "blimp/engine/mojo/blob_channel_service.h"
6 6
7 #include <string> 7 #include <string>
8 #include <unordered_map> 8 #include <unordered_map>
9 #include <utility> 9 #include <utility>
10 #include <vector> 10 #include <vector>
11 11
12 #include "base/memory/ptr_util.h" 12 #include "base/memory/ptr_util.h"
13 #include "base/task_runner_util.h" 13 #include "base/task_runner_util.h"
14 #include "base/threading/thread.h" 14 #include "base/threading/thread.h"
15 #include "blimp/net/blob_channel/blob_channel_sender.h" 15 #include "blimp/net/blob_channel/blob_channel_sender.h"
16 #include "mojo/public/cpp/bindings/message.h"
16 #include "mojo/public/cpp/system/buffer.h" 17 #include "mojo/public/cpp/system/buffer.h"
17 18
18 namespace blimp { 19 namespace blimp {
19 namespace engine { 20 namespace engine {
20 namespace { 21 namespace {
21 22
22 std::vector<BlobChannelSender::CacheStateEntry> 23 std::vector<BlobChannelSender::CacheStateEntry>
23 GetCachedBlobIdsFromWeakPtr(base::WeakPtr<BlobChannelSender> sender) { 24 GetCachedBlobIdsFromWeakPtr(base::WeakPtr<BlobChannelSender> sender) {
24 if (sender) { 25 if (sender) {
25 return sender->GetCachedBlobIds(); 26 return sender->GetCachedBlobIds();
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
66 response_callback.Run(std::move(cache_state)); 67 response_callback.Run(std::move(cache_state));
67 } 68 }
68 69
69 void BlobChannelService::PutBlob(const std::string& id, 70 void BlobChannelService::PutBlob(const std::string& id,
70 mojo::ScopedSharedBufferHandle data, 71 mojo::ScopedSharedBufferHandle data,
71 uint32_t size) { 72 uint32_t size) {
72 DCHECK(thread_checker_.CalledOnValidThread()); 73 DCHECK(thread_checker_.CalledOnValidThread());
73 74
74 // Map |data| into the address space and copy out its contents. 75 // Map |data| into the address space and copy out its contents.
75 if (!data.is_valid()) { 76 if (!data.is_valid()) {
76 LOG(ERROR) << "Invalid data handle received from renderer process."; 77 mojo::ReportBadMessage(
78 "Invalid data handle received from renderer process.");
77 return; 79 return;
78 } 80 }
79 81
80 if (size > kMaxBlobSizeBytes) { 82 if (size > kMaxBlobSizeBytes) {
81 LOG(ERROR) << "Blob size too big: " << size; 83 mojo::ReportBadMessage("Blob size too large.");
82 return; 84 return;
83 } 85 }
84 86
85 mojo::ScopedSharedBufferMapping mapping = data->Map(size); 87 mojo::ScopedSharedBufferMapping mapping = data->Map(size);
86 CHECK(mapping) << "Failed to mmap region of " << size << " bytes."; 88 CHECK(mapping) << "Failed to mmap region of " << size << " bytes.";
87 89
88 scoped_refptr<BlobData> new_blob(new BlobData); 90 scoped_refptr<BlobData> new_blob(new BlobData);
89 new_blob->data.assign(reinterpret_cast<const char*>(mapping.get()), size); 91 new_blob->data.assign(reinterpret_cast<const char*>(mapping.get()), size);
90 92
91 blob_sender_task_runner_->PostTask(FROM_HERE, 93 blob_sender_task_runner_->PostTask(FROM_HERE,
(...skipping 14 matching lines...) Expand all
106 108
107 void BlobChannelService::BindRequest( 109 void BlobChannelService::BindRequest(
108 mojo::InterfaceRequest<mojom::BlobChannel> request) { 110 mojo::InterfaceRequest<mojom::BlobChannel> request) {
109 DCHECK(thread_checker_.CalledOnValidThread()); 111 DCHECK(thread_checker_.CalledOnValidThread());
110 112
111 bindings_.AddBinding(this, std::move(request)); 113 bindings_.AddBinding(this, std::move(request));
112 } 114 }
113 115
114 } // namespace engine 116 } // namespace engine
115 } // namespace blimp 117 } // namespace blimp
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698