OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "ipc/ipc_message.h" | 5 #include "ipc/ipc_message.h" |
6 | 6 |
7 #include <limits.h> | 7 #include <limits.h> |
8 | 8 |
9 #include "base/atomic_sequence_num.h" | 9 #include "base/atomic_sequence_num.h" |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
142 const char* pickle_end = | 142 const char* pickle_end = |
143 base::Pickle::FindNext(sizeof(Header), range_start, range_end); | 143 base::Pickle::FindNext(sizeof(Header), range_start, range_end); |
144 if (!pickle_end) | 144 if (!pickle_end) |
145 return; | 145 return; |
146 info->pickle_end = pickle_end; | 146 info->pickle_end = pickle_end; |
147 | 147 |
148 #if USE_ATTACHMENT_BROKER | 148 #if USE_ATTACHMENT_BROKER |
149 // The data is not copied. | 149 // The data is not copied. |
150 size_t pickle_len = static_cast<size_t>(pickle_end - range_start); | 150 size_t pickle_len = static_cast<size_t>(pickle_end - range_start); |
151 Message message(range_start, static_cast<int>(pickle_len)); | 151 Message message(range_start, static_cast<int>(pickle_len)); |
152 int num_attachments = message.header()->num_brokered_attachments; | 152 size_t num_attachments = message.header()->num_brokered_attachments; |
153 | 153 |
154 // Check for possible overflows. | 154 // Check for possible overflows. |
155 size_t max_size_t = std::numeric_limits<size_t>::max(); | 155 size_t max_size_t = std::numeric_limits<size_t>::max(); |
156 if (num_attachments >= max_size_t / BrokerableAttachment::kNonceSize) | 156 if (num_attachments >= max_size_t / BrokerableAttachment::kNonceSize) |
157 return; | 157 return; |
158 | 158 |
159 size_t attachment_length = num_attachments * BrokerableAttachment::kNonceSize; | 159 size_t attachment_length = num_attachments * BrokerableAttachment::kNonceSize; |
160 if (pickle_len > max_size_t - attachment_length) | 160 if (pickle_len > max_size_t - attachment_length) |
161 return; | 161 return; |
162 | 162 |
163 // Check whether the range includes the attachments. | 163 // Check whether the range includes the attachments. |
164 size_t buffer_length = static_cast<size_t>(range_end - range_start); | 164 size_t buffer_length = static_cast<size_t>(range_end - range_start); |
165 if (buffer_length < attachment_length + pickle_len) | 165 if (buffer_length < attachment_length + pickle_len) |
166 return; | 166 return; |
167 | 167 |
168 for (int i = 0; i < num_attachments; ++i) { | 168 for (size_t i = 0; i < num_attachments; ++i) { |
169 const char* attachment_start = | 169 const char* attachment_start = |
170 pickle_end + i * BrokerableAttachment::kNonceSize; | 170 pickle_end + i * BrokerableAttachment::kNonceSize; |
171 BrokerableAttachment::AttachmentId id(attachment_start, | 171 BrokerableAttachment::AttachmentId id(attachment_start, |
172 BrokerableAttachment::kNonceSize); | 172 BrokerableAttachment::kNonceSize); |
173 info->attachment_ids.push_back(id); | 173 info->attachment_ids.push_back(id); |
174 } | 174 } |
175 info->message_end = | 175 info->message_end = |
176 pickle_end + num_attachments * BrokerableAttachment::kNonceSize; | 176 pickle_end + num_attachments * BrokerableAttachment::kNonceSize; |
177 #else | 177 #else |
178 info->message_end = pickle_end; | 178 info->message_end = pickle_end; |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
217 bool Message::HasMojoHandles() const { | 217 bool Message::HasMojoHandles() const { |
218 return attachment_set_.get() && attachment_set_->num_mojo_handles() > 0; | 218 return attachment_set_.get() && attachment_set_->num_mojo_handles() > 0; |
219 } | 219 } |
220 | 220 |
221 bool Message::HasBrokerableAttachments() const { | 221 bool Message::HasBrokerableAttachments() const { |
222 return attachment_set_.get() && | 222 return attachment_set_.get() && |
223 attachment_set_->num_brokerable_attachments() > 0; | 223 attachment_set_->num_brokerable_attachments() > 0; |
224 } | 224 } |
225 | 225 |
226 } // namespace IPC | 226 } // namespace IPC |
OLD | NEW |