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(); | |
292 for (size_t i = 0; i < header->num_dispatchers; ++i) { | 293 for (size_t i = 0; i < header->num_dispatchers; ++i) { |
293 const DispatcherHeader& dh = dispatcher_headers[i]; | 294 const DispatcherHeader& dh = dispatcher_headers[i]; |
294 Type type = static_cast<Type>(dh.type); | 295 Type type = static_cast<Type>(dh.type); |
295 | 296 |
296 size_t next_payload_index = data_payload_index + dh.num_bytes; | 297 size_t next_payload_index = data_payload_index + dh.num_bytes; |
297 if (msg->num_payload_bytes() < next_payload_index || | 298 if (msg->num_payload_bytes() < next_payload_index || |
298 next_payload_index < data_payload_index) { | 299 next_payload_index < data_payload_index) { |
299 return MOJO_RESULT_UNKNOWN; | 300 return MOJO_RESULT_UNKNOWN; |
300 } | 301 } |
301 | 302 |
302 size_t next_port_index = port_index + dh.num_ports; | 303 size_t next_port_index = port_index + dh.num_ports; |
303 if (msg->num_ports() < next_port_index || next_port_index < port_index) | 304 if (msg->num_ports() < next_port_index || next_port_index < port_index) |
304 return MOJO_RESULT_UNKNOWN; | 305 return MOJO_RESULT_UNKNOWN; |
305 | 306 |
306 size_t next_platform_handle_index = | 307 size_t next_platform_handle_index = |
307 platform_handle_index + dh.num_platform_handles; | 308 platform_handle_index + dh.num_platform_handles; |
308 if (msg->num_handles() < next_platform_handle_index || | 309 if ((msg_handles && msg_handles->size() < next_platform_handle_index) || |
Ken Rockot(use gerrit already)
2016/05/25 15:48:12
nit: Could you create a local num_handles near msg
Anand Mistry (off Chromium)
2016/05/25 23:36:38
Done.
| |
309 next_platform_handle_index < platform_handle_index) { | 310 next_platform_handle_index < platform_handle_index) { |
310 return MOJO_RESULT_UNKNOWN; | 311 return MOJO_RESULT_UNKNOWN; |
311 } | 312 } |
312 | 313 |
313 PlatformHandle* out_handles = | 314 PlatformHandle* out_handles = |
314 msg->num_handles() ? msg->handles() + platform_handle_index : nullptr; | 315 (msg_handles && msg_handles->size()) ? |
316 msg_handles->data() + platform_handle_index : nullptr; | |
315 dispatchers[i].dispatcher = Dispatcher::Deserialize( | 317 dispatchers[i].dispatcher = Dispatcher::Deserialize( |
316 type, dispatcher_data, dh.num_bytes, msg->ports() + port_index, | 318 type, dispatcher_data, dh.num_bytes, msg->ports() + port_index, |
317 dh.num_ports, out_handles, dh.num_platform_handles); | 319 dh.num_ports, out_handles, dh.num_platform_handles); |
318 if (!dispatchers[i].dispatcher) | 320 if (!dispatchers[i].dispatcher) |
319 return MOJO_RESULT_UNKNOWN; | 321 return MOJO_RESULT_UNKNOWN; |
320 | 322 |
321 dispatcher_data += dh.num_bytes; | 323 dispatcher_data += dh.num_bytes; |
322 data_payload_index = next_payload_index; | 324 data_payload_index = next_payload_index; |
323 port_index = next_port_index; | 325 port_index = next_port_index; |
324 platform_handle_index = next_platform_handle_index; | 326 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() << "]"; | 544 << " endpoint " << endpoint_ << " [port=" << port_.name() << "]"; |
543 } | 545 } |
544 } | 546 } |
545 #endif | 547 #endif |
546 | 548 |
547 awakables_.AwakeForStateChange(GetHandleSignalsStateNoLock()); | 549 awakables_.AwakeForStateChange(GetHandleSignalsStateNoLock()); |
548 } | 550 } |
549 | 551 |
550 } // namespace edk | 552 } // namespace edk |
551 } // namespace mojo | 553 } // namespace mojo |
OLD | NEW |