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

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

Issue 725733002: IPC::ChannelMojo: Make IPC handling robust against bad messages. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 1 month 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 | « no previous file | 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) {
viettrungluu 2014/11/13 20:27:57 You should probably document in the header what th
Hajime Morrita 2014/11/13 21:01:18 Done.
104 DLOG(WARNING) << "Got inconsistent message from client.";
viettrungluu 2014/11/13 20:27:57 LOG(ERROR)? This seems pretty serious.
Hajime Morrita 2014/11/13 21:01:18 Done.
105 return false;
106 }
107
104 set_state(STATE_READY); 108 set_state(STATE_READY);
105 109 DCHECK(server_pipe_.is_valid());
viettrungluu 2014/11/13 20:27:57 CHECK?
Hajime Morrita 2014/11/13 21:01:18 Done.
106 delegate()->OnPipeAvailable( 110 delegate()->OnPipeAvailable(
107 mojo::embedder::ScopedPlatformHandle(server_pipe_.release())); 111 mojo::embedder::ScopedPlatformHandle(server_pipe_.release()));
108 112
109 return true; 113 return true;
110 } 114 }
111 115
112 // MojoBootstrap for client processes. You should create the instance 116 // MojoBootstrap for client processes. You should create the instance
113 // using MojoBootstrap::Create(). 117 // using MojoBootstrap::Create().
114 class MojoClientBootstrap : public MojoBootstrap { 118 class MojoClientBootstrap : public MojoBootstrap {
115 public: 119 public:
116 MojoClientBootstrap(); 120 MojoClientBootstrap();
117 121
118 void OnClientLaunched(base::ProcessHandle process) override; 122 void OnClientLaunched(base::ProcessHandle process) override;
119 123
120 private: 124 private:
121 // Listener implementations 125 // Listener implementations
122 bool OnMessageReceived(const Message& message) override; 126 bool OnMessageReceived(const Message& message) override;
123 void OnChannelConnected(int32 peer_pid) override; 127 void OnChannelConnected(int32 peer_pid) override;
124 128
125 DISALLOW_COPY_AND_ASSIGN(MojoClientBootstrap); 129 DISALLOW_COPY_AND_ASSIGN(MojoClientBootstrap);
126 }; 130 };
127 131
128 MojoClientBootstrap::MojoClientBootstrap() { 132 MojoClientBootstrap::MojoClientBootstrap() {
129 } 133 }
130 134
131 bool MojoClientBootstrap::OnMessageReceived(const Message& message) { 135 bool MojoClientBootstrap::OnMessageReceived(const Message& message) {
136 if (STATE_INITIALIZED != state()) {
viettrungluu 2014/11/13 20:27:57 state() != STATE_INITIALIZED
Hajime Morrita 2014/11/13 21:01:18 Done.
137 DLOG(WARNING) << "Got inconsistent message from server.";
viettrungluu 2014/11/13 20:27:57 LOG(ERROR)?
Hajime Morrita 2014/11/13 21:01:18 Done.
138 return false;
139 }
140
132 PlatformFileForTransit pipe; 141 PlatformFileForTransit pipe;
133 PickleIterator iter(message); 142 PickleIterator iter(message);
134 if (!ParamTraits<PlatformFileForTransit>::Read(&message, &iter, &pipe)) { 143 if (!ParamTraits<PlatformFileForTransit>::Read(&message, &iter, &pipe)) {
135 DLOG(WARNING) << "Failed to read a file handle from bootstrap channel."; 144 DLOG(WARNING) << "Failed to read a file handle from bootstrap channel.";
136 message.set_dispatch_error(); 145 message.set_dispatch_error();
137 return false; 146 return false;
138 } 147 }
139 148
140 // Sends ACK back. 149 // Sends ACK back.
141 Send(new Message()); 150 Send(new Message());
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
217 int MojoBootstrap::GetClientFileDescriptor() const { 226 int MojoBootstrap::GetClientFileDescriptor() const {
218 return channel_->GetClientFileDescriptor(); 227 return channel_->GetClientFileDescriptor();
219 } 228 }
220 229
221 base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() { 230 base::ScopedFD MojoBootstrap::TakeClientFileDescriptor() {
222 return channel_->TakeClientFileDescriptor(); 231 return channel_->TakeClientFileDescriptor();
223 } 232 }
224 #endif // defined(OS_POSIX) && !defined(OS_NACL) 233 #endif // defined(OS_POSIX) && !defined(OS_NACL)
225 234
226 } // namespace IPC 235 } // namespace IPC
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698