OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 "mojo/edk/system/message_pipe_dispatcher.h" | 5 #include "mojo/edk/system/message_pipe_dispatcher.h" |
6 | 6 |
7 #include <limits> | 7 #include <limits> |
8 #include <memory> | 8 #include <memory> |
9 | 9 |
10 #include "base/logging.h" | 10 #include "base/logging.h" |
(...skipping 271 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
282 CHECK(handles); | 282 CHECK(handles); |
283 std::vector<DispatcherInTransit> dispatchers(header->num_dispatchers); | 283 std::vector<DispatcherInTransit> dispatchers(header->num_dispatchers); |
284 size_t data_payload_index = sizeof(MessageHeader) + | 284 size_t data_payload_index = sizeof(MessageHeader) + |
285 header->num_dispatchers * sizeof(DispatcherHeader); | 285 header->num_dispatchers * sizeof(DispatcherHeader); |
286 if (data_payload_index > header->header_size) | 286 if (data_payload_index > header->header_size) |
287 return MOJO_RESULT_UNKNOWN; | 287 return MOJO_RESULT_UNKNOWN; |
288 const char* dispatcher_data = reinterpret_cast<const char*>( | 288 const char* dispatcher_data = reinterpret_cast<const char*>( |
289 dispatcher_headers + header->num_dispatchers); | 289 dispatcher_headers + header->num_dispatchers); |
290 size_t port_index = 0; | 290 size_t port_index = 0; |
291 size_t platform_handle_index = 0; | 291 size_t platform_handle_index = 0; |
| 292 ScopedPlatformHandleVectorPtr msg_handles = msg->TakeHandles(); |
| 293 const size_t num_msg_handles = msg_handles ? msg_handles->size() : 0; |
292 for (size_t i = 0; i < header->num_dispatchers; ++i) { | 294 for (size_t i = 0; i < header->num_dispatchers; ++i) { |
293 const DispatcherHeader& dh = dispatcher_headers[i]; | 295 const DispatcherHeader& dh = dispatcher_headers[i]; |
294 Type type = static_cast<Type>(dh.type); | 296 Type type = static_cast<Type>(dh.type); |
295 | 297 |
296 size_t next_payload_index = data_payload_index + dh.num_bytes; | 298 size_t next_payload_index = data_payload_index + dh.num_bytes; |
297 if (msg->num_payload_bytes() < next_payload_index || | 299 if (msg->num_payload_bytes() < next_payload_index || |
298 next_payload_index < data_payload_index) { | 300 next_payload_index < data_payload_index) { |
299 return MOJO_RESULT_UNKNOWN; | 301 return MOJO_RESULT_UNKNOWN; |
300 } | 302 } |
301 | 303 |
302 size_t next_port_index = port_index + dh.num_ports; | 304 size_t next_port_index = port_index + dh.num_ports; |
303 if (msg->num_ports() < next_port_index || next_port_index < port_index) | 305 if (msg->num_ports() < next_port_index || next_port_index < port_index) |
304 return MOJO_RESULT_UNKNOWN; | 306 return MOJO_RESULT_UNKNOWN; |
305 | 307 |
306 size_t next_platform_handle_index = | 308 size_t next_platform_handle_index = |
307 platform_handle_index + dh.num_platform_handles; | 309 platform_handle_index + dh.num_platform_handles; |
308 if (msg->num_handles() < next_platform_handle_index || | 310 if (num_msg_handles < next_platform_handle_index || |
309 next_platform_handle_index < platform_handle_index) { | 311 next_platform_handle_index < platform_handle_index) { |
310 return MOJO_RESULT_UNKNOWN; | 312 return MOJO_RESULT_UNKNOWN; |
311 } | 313 } |
312 | 314 |
313 PlatformHandle* out_handles = | 315 PlatformHandle* out_handles = |
314 msg->num_handles() ? msg->handles() + platform_handle_index : nullptr; | 316 num_msg_handles ? msg_handles->data() + platform_handle_index |
| 317 : nullptr; |
315 dispatchers[i].dispatcher = Dispatcher::Deserialize( | 318 dispatchers[i].dispatcher = Dispatcher::Deserialize( |
316 type, dispatcher_data, dh.num_bytes, msg->ports() + port_index, | 319 type, dispatcher_data, dh.num_bytes, msg->ports() + port_index, |
317 dh.num_ports, out_handles, dh.num_platform_handles); | 320 dh.num_ports, out_handles, dh.num_platform_handles); |
318 if (!dispatchers[i].dispatcher) | 321 if (!dispatchers[i].dispatcher) |
319 return MOJO_RESULT_UNKNOWN; | 322 return MOJO_RESULT_UNKNOWN; |
320 | 323 |
321 dispatcher_data += dh.num_bytes; | 324 dispatcher_data += dh.num_bytes; |
322 data_payload_index = next_payload_index; | 325 data_payload_index = next_payload_index; |
323 port_index = next_port_index; | 326 port_index = next_port_index; |
324 platform_handle_index = next_platform_handle_index; | 327 platform_handle_index = next_platform_handle_index; |
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
542 << " endpoint " << endpoint_ << " [port=" << port_.name() << "]"; | 545 << " endpoint " << endpoint_ << " [port=" << port_.name() << "]"; |
543 } | 546 } |
544 } | 547 } |
545 #endif | 548 #endif |
546 | 549 |
547 awakables_.AwakeForStateChange(GetHandleSignalsStateNoLock()); | 550 awakables_.AwakeForStateChange(GetHandleSignalsStateNoLock()); |
548 } | 551 } |
549 | 552 |
550 } // namespace edk | 553 } // namespace edk |
551 } // namespace mojo | 554 } // namespace mojo |
OLD | NEW |