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

Side by Side Diff: ipc/mojo/ipc_mojo_bootstrap.cc

Issue 892503002: Revert of Revert of IPC::ChannelMojo: Make IPC handling robust against bad messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 10 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 | « ipc/mojo/ipc_mojo_bootstrap.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/mojo/ipc_mojo_bootstrap.h" 5 #include "ipc/mojo/ipc_mojo_bootstrap.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/process/process_handle.h" 8 #include "base/process/process_handle.h"
9 #include "ipc/ipc_message_utils.h" 9 #include "ipc/ipc_message_utils.h"
10 #include "ipc/ipc_platform_file.h" 10 #include "ipc/ipc_platform_file.h"
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 SendClientPipeIfReady(); 93 SendClientPipeIfReady();
94 } 94 }
95 95
96 void MojoServerBootstrap::OnChannelConnected(int32 peer_pid) { 96 void MojoServerBootstrap::OnChannelConnected(int32 peer_pid) {
97 DCHECK_EQ(state(), STATE_INITIALIZED); 97 DCHECK_EQ(state(), STATE_INITIALIZED);
98 connected_ = true; 98 connected_ = true;
99 SendClientPipeIfReady(); 99 SendClientPipeIfReady();
100 } 100 }
101 101
102 bool MojoServerBootstrap::OnMessageReceived(const Message&) { 102 bool MojoServerBootstrap::OnMessageReceived(const Message&) {
103 DCHECK_EQ(state(), STATE_WAITING_ACK); 103 if (state() != STATE_WAITING_ACK) {
104 set_state(STATE_ERROR);
105 LOG(ERROR) << "Got inconsistent message from client.";
106 return false;
107 }
108
104 set_state(STATE_READY); 109 set_state(STATE_READY);
105 110 CHECK(server_pipe_.is_valid());
106 delegate()->OnPipeAvailable( 111 delegate()->OnPipeAvailable(
107 mojo::embedder::ScopedPlatformHandle(server_pipe_.release())); 112 mojo::embedder::ScopedPlatformHandle(server_pipe_.release()));
108 113
109 return true; 114 return true;
110 } 115 }
111 116
112 // MojoBootstrap for client processes. You should create the instance 117 // MojoBootstrap for client processes. You should create the instance
113 // using MojoBootstrap::Create(). 118 // using MojoBootstrap::Create().
114 class MojoClientBootstrap : public MojoBootstrap { 119 class MojoClientBootstrap : public MojoBootstrap {
115 public: 120 public:
116 MojoClientBootstrap(); 121 MojoClientBootstrap();
117 122
118 void OnClientLaunched(base::ProcessHandle process) override; 123 void OnClientLaunched(base::ProcessHandle process) override;
119 124
120 private: 125 private:
121 // Listener implementations 126 // Listener implementations
122 bool OnMessageReceived(const Message& message) override; 127 bool OnMessageReceived(const Message& message) override;
123 void OnChannelConnected(int32 peer_pid) override; 128 void OnChannelConnected(int32 peer_pid) override;
124 129
125 DISALLOW_COPY_AND_ASSIGN(MojoClientBootstrap); 130 DISALLOW_COPY_AND_ASSIGN(MojoClientBootstrap);
126 }; 131 };
127 132
128 MojoClientBootstrap::MojoClientBootstrap() { 133 MojoClientBootstrap::MojoClientBootstrap() {
129 } 134 }
130 135
131 bool MojoClientBootstrap::OnMessageReceived(const Message& message) { 136 bool MojoClientBootstrap::OnMessageReceived(const Message& message) {
137 if (state() != STATE_INITIALIZED) {
138 set_state(STATE_ERROR);
139 LOG(ERROR) << "Got inconsistent message from server.";
140 return false;
141 }
142
132 PlatformFileForTransit pipe; 143 PlatformFileForTransit pipe;
133 PickleIterator iter(message); 144 PickleIterator iter(message);
134 if (!ParamTraits<PlatformFileForTransit>::Read(&message, &iter, &pipe)) { 145 if (!ParamTraits<PlatformFileForTransit>::Read(&message, &iter, &pipe)) {
135 DLOG(WARNING) << "Failed to read a file handle from bootstrap channel."; 146 DLOG(WARNING) << "Failed to read a file handle from bootstrap channel.";
136 message.set_dispatch_error(); 147 message.set_dispatch_error();
137 return false; 148 return false;
138 } 149 }
139 150
140 // Sends ACK back. 151 // Sends ACK back.
141 Send(new Message()); 152 Send(new Message());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 int MojoBootstrap::GetClientFileDescriptor() const { 228 int MojoBootstrap::GetClientFileDescriptor() const {
218 return channel_->GetClientFileDescriptor(); 229 return channel_->GetClientFileDescriptor();
219 } 230 }
220 231
221 base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() { 232 base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() {
222 return channel_->TakeClientFileDescriptor(); 233 return channel_->TakeClientFileDescriptor();
223 } 234 }
224 #endif // defined(OS_POSIX) && !defined(OS_NACL) 235 #endif // defined(OS_POSIX) && !defined(OS_NACL)
225 236
226 } // namespace IPC 237 } // namespace IPC
OLDNEW
« no previous file with comments | « ipc/mojo/ipc_mojo_bootstrap.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698