| OLD | NEW |
| 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 "mojo/edk/system/node_channel.h" | 5 #include "mojo/edk/system/node_channel.h" |
| 6 | 6 |
| 7 #include <cstring> | 7 #include <cstring> |
| 8 #include <limits> | 8 #include <limits> |
| 9 #include <sstream> | 9 #include <sstream> |
| 10 | 10 |
| (...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 387 | 387 |
| 388 RequestContext request_context(RequestContext::Source::SYSTEM); | 388 RequestContext request_context(RequestContext::Source::SYSTEM); |
| 389 | 389 |
| 390 #if defined(OS_WIN) | 390 #if defined(OS_WIN) |
| 391 // If we receive handles from a known process, rewrite them to our own | 391 // If we receive handles from a known process, rewrite them to our own |
| 392 // process. This can occur when a privileged node receives handles directly | 392 // process. This can occur when a privileged node receives handles directly |
| 393 // from a privileged descendant. | 393 // from a privileged descendant. |
| 394 { | 394 { |
| 395 base::AutoLock lock(remote_process_handle_lock_); | 395 base::AutoLock lock(remote_process_handle_lock_); |
| 396 if (handles && remote_process_handle_ != base::kNullProcessHandle) { | 396 if (handles && remote_process_handle_ != base::kNullProcessHandle) { |
| 397 // Note that we explicitly mark the handles as being owned by the sending |
| 398 // process before rewriting them, in order to accommodate RewriteHandles' |
| 399 // internal sanity checks. |
| 400 for (auto& handle : *handles) |
| 401 handle.owning_process = remote_process_handle_; |
| 397 if (!Channel::Message::RewriteHandles(remote_process_handle_, | 402 if (!Channel::Message::RewriteHandles(remote_process_handle_, |
| 398 base::GetCurrentProcessHandle(), | 403 base::GetCurrentProcessHandle(), |
| 399 handles->data(), handles->size())) { | 404 handles->data(), handles->size())) { |
| 400 DLOG(ERROR) << "Received one or more invalid handles."; | 405 DLOG(ERROR) << "Received one or more invalid handles."; |
| 401 } | 406 } |
| 407 } else if (handles) { |
| 408 // Handles received by an unknown process must already be owned by us. |
| 409 for (auto& handle : *handles) |
| 410 handle.owning_process = base::GetCurrentProcessHandle(); |
| 402 } | 411 } |
| 403 } | 412 } |
| 404 #elif defined(OS_MACOSX) && !defined(OS_IOS) | 413 #elif defined(OS_MACOSX) && !defined(OS_IOS) |
| 405 // If we're not the root, receive any mach ports from the message. If we're | 414 // If we're not the root, receive any mach ports from the message. If we're |
| 406 // the root, the only message containing mach ports should be a | 415 // the root, the only message containing mach ports should be a |
| 407 // RELAY_PORTS_MESSAGE. | 416 // RELAY_PORTS_MESSAGE. |
| 408 { | 417 { |
| 409 MachPortRelay* relay = delegate_->GetMachPortRelay(); | 418 MachPortRelay* relay = delegate_->GetMachPortRelay(); |
| 410 if (handles && !relay) { | 419 if (handles && !relay) { |
| 411 if (!MachPortRelay::ReceivePorts(handles.get())) { | 420 if (!MachPortRelay::ReceivePorts(handles.get())) { |
| (...skipping 299 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 711 | 720 |
| 712 base::AutoLock lock(channel_lock_); | 721 base::AutoLock lock(channel_lock_); |
| 713 if (!channel_) | 722 if (!channel_) |
| 714 DLOG(ERROR) << "Dropping message on closed channel."; | 723 DLOG(ERROR) << "Dropping message on closed channel."; |
| 715 else | 724 else |
| 716 channel_->Write(std::move(message)); | 725 channel_->Write(std::move(message)); |
| 717 } | 726 } |
| 718 | 727 |
| 719 } // namespace edk | 728 } // namespace edk |
| 720 } // namespace mojo | 729 } // namespace mojo |
| OLD | NEW |