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

Side by Side Diff: mojo/edk/system/node_controller.cc

Issue 1988413002: [mojo-edk] Sanity checks on ports message parsing (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@2704
Patch Set: Created 4 years, 7 months 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 | « mojo/edk/system/node_controller.h ('k') | mojo/edk/system/ports/message.h » ('j') | 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 "mojo/edk/system/node_controller.h" 5 #include "mojo/edk/system/node_controller.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <limits> 8 #include <limits>
9 9
10 #include "base/bind.h" 10 #include "base/bind.h"
(...skipping 768 matching lines...) Expand 10 before | Expand all | Expand 10 after
779 while (!message_queue.empty()) { 779 while (!message_queue.empty()) {
780 broker->RelayPortsMessage(destination, std::move(message_queue.front())); 780 broker->RelayPortsMessage(destination, std::move(message_queue.front()));
781 message_queue.pop(); 781 message_queue.pop();
782 } 782 }
783 } 783 }
784 #endif 784 #endif
785 785
786 DVLOG(1) << "Child " << name_ << " accepted by broker " << broker_name; 786 DVLOG(1) << "Child " << name_ << " accepted by broker " << broker_name;
787 } 787 }
788 788
789 void NodeController::OnPortsMessage(Channel::MessagePtr channel_message) { 789 void NodeController::OnPortsMessage(const ports::NodeName& from_node,
790 Channel::MessagePtr channel_message) {
790 DCHECK(io_task_runner_->RunsTasksOnCurrentThread()); 791 DCHECK(io_task_runner_->RunsTasksOnCurrentThread());
791 792
792 void* data; 793 void* data;
793 size_t num_data_bytes; 794 size_t num_data_bytes;
794 NodeChannel::GetPortsMessageData( 795 NodeChannel::GetPortsMessageData(
795 channel_message.get(), &data, &num_data_bytes); 796 channel_message.get(), &data, &num_data_bytes);
797 if (!num_data_bytes) {
798 DropPeer(from_node);
799 return;
800 }
796 801
797 size_t num_header_bytes, num_payload_bytes, num_ports_bytes; 802 size_t num_header_bytes, num_payload_bytes, num_ports_bytes;
798 ports::Message::Parse(data, 803 if (!ports::Message::Parse(data,
799 num_data_bytes, 804 num_data_bytes,
800 &num_header_bytes, 805 &num_header_bytes,
801 &num_payload_bytes, 806 &num_payload_bytes,
802 &num_ports_bytes); 807 &num_ports_bytes)) {
808 DropPeer(from_node);
809 return;
810 }
803 811
804 CHECK(channel_message); 812 CHECK(channel_message);
805 ports::ScopedMessage message( 813 ports::ScopedMessage message(
806 new PortsMessage(num_header_bytes, 814 new PortsMessage(num_header_bytes,
807 num_payload_bytes, 815 num_payload_bytes,
808 num_ports_bytes, 816 num_ports_bytes,
809 std::move(channel_message))); 817 std::move(channel_message)));
810 818
811 node_->AcceptMessage(std::move(message)); 819 node_->AcceptMessage(std::move(message));
812 AcceptIncomingMessages(); 820 AcceptIncomingMessages();
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
921 // process. At this point, if the port extraction failed, either something 929 // process. At this point, if the port extraction failed, either something
922 // went wrong in the mach stuff, or the remote process died. 930 // went wrong in the mach stuff, or the remote process died.
923 LOG(ERROR) << "Error on receiving Mach ports " << from_node 931 LOG(ERROR) << "Error on receiving Mach ports " << from_node
924 << ". Dropping message."; 932 << ". Dropping message.";
925 return; 933 return;
926 } 934 }
927 #endif // defined(OS_WIN) 935 #endif // defined(OS_WIN)
928 936
929 if (destination == name_) { 937 if (destination == name_) {
930 // Great, we can deliver this message locally. 938 // Great, we can deliver this message locally.
931 OnPortsMessage(std::move(message)); 939 OnPortsMessage(from_node, std::move(message));
932 return; 940 return;
933 } 941 }
934 942
935 scoped_refptr<NodeChannel> peer = GetPeerChannel(destination); 943 scoped_refptr<NodeChannel> peer = GetPeerChannel(destination);
936 if (peer) 944 if (peer)
937 peer->PortsMessage(std::move(message)); 945 peer->PortsMessage(std::move(message));
938 else 946 else
939 DLOG(ERROR) << "Dropping relay message for unknown node " << destination; 947 DLOG(ERROR) << "Dropping relay message for unknown node " << destination;
940 } 948 }
941 #endif 949 #endif
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after
983 shutdown_callback_.Reset(); 991 shutdown_callback_.Reset();
984 } 992 }
985 993
986 DCHECK(!callback.is_null()); 994 DCHECK(!callback.is_null());
987 995
988 callback.Run(); 996 callback.Run();
989 } 997 }
990 998
991 } // namespace edk 999 } // namespace edk
992 } // namespace mojo 1000 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/edk/system/node_controller.h ('k') | mojo/edk/system/ports/message.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698