OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/ipc_channel_win.h" | 5 #include "ipc/ipc_channel_win.h" |
6 | 6 |
7 #include <windows.h> | 7 #include <windows.h> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
11 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
12 #include "base/logging.h" | 12 #include "base/logging.h" |
13 #include "base/pickle.h" | |
13 #include "base/process_util.h" | 14 #include "base/process_util.h" |
14 #include "base/rand_util.h" | 15 #include "base/rand_util.h" |
15 #include "base/string_number_conversions.h" | 16 #include "base/string_number_conversions.h" |
16 #include "base/threading/thread_checker.h" | 17 #include "base/threading/thread_checker.h" |
17 #include "base/utf_string_conversions.h" | 18 #include "base/utf_string_conversions.h" |
18 #include "base/win/scoped_handle.h" | 19 #include "base/win/scoped_handle.h" |
19 #include "ipc/ipc_listener.h" | 20 #include "ipc/ipc_listener.h" |
20 #include "ipc/ipc_logging.h" | 21 #include "ipc/ipc_logging.h" |
21 #include "ipc/ipc_message_utils.h" | 22 #include "ipc/ipc_message_utils.h" |
22 | 23 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
146 | 147 |
147 bool Channel::ChannelImpl::WillDispatchInputMessage(Message* msg) { | 148 bool Channel::ChannelImpl::WillDispatchInputMessage(Message* msg) { |
148 // Make sure we get a hello when client validation is required. | 149 // Make sure we get a hello when client validation is required. |
149 if (validate_client_) | 150 if (validate_client_) |
150 return IsHelloMessage(*msg); | 151 return IsHelloMessage(*msg); |
151 return true; | 152 return true; |
152 } | 153 } |
153 | 154 |
154 void Channel::ChannelImpl::HandleHelloMessage(const Message& msg) { | 155 void Channel::ChannelImpl::HandleHelloMessage(const Message& msg) { |
155 // The hello message contains one parameter containing the PID. | 156 // The hello message contains one parameter containing the PID. |
156 MessageIterator it = MessageIterator(msg); | 157 PickleIterator it(msg); |
157 int32 claimed_pid = it.NextInt(); | 158 int32 claimed_pid; |
158 if (validate_client_ && (it.NextInt() != client_secret_)) { | 159 if (!it.ReadInt(&claimed_pid)) { |
159 NOTREACHED(); | 160 NOTREACHED(); |
160 // Something went wrong. Abort connection. | |
161 Close(); | 161 Close(); |
162 listener()->OnChannelError(); | 162 listener()->OnChannelError(); |
163 return; | 163 return; |
164 } | 164 } |
165 | |
166 if (validate_client_) { | |
167 int32 secret; | |
168 bool result = it.ReadInt(&secret); | |
169 if (!result || secret != client_secret_) { | |
170 NOTREACHED(); | |
jam
2012/12/17 16:21:57
seems unfortunate to duplicate this little block t
| |
171 Close(); | |
172 listener()->OnChannelError(); | |
173 return; | |
174 } | |
175 } | |
176 | |
165 peer_pid_ = claimed_pid; | 177 peer_pid_ = claimed_pid; |
166 // validation completed. | 178 // Validation completed. |
167 validate_client_ = false; | 179 validate_client_ = false; |
168 listener()->OnChannelConnected(claimed_pid); | 180 listener()->OnChannelConnected(claimed_pid); |
169 } | 181 } |
170 | 182 |
171 bool Channel::ChannelImpl::DidEmptyInputBuffers() { | 183 bool Channel::ChannelImpl::DidEmptyInputBuffers() { |
172 // We don't need to do anything here. | 184 // We don't need to do anything here. |
173 return true; | 185 return true; |
174 } | 186 } |
175 | 187 |
176 // static | 188 // static |
(...skipping 323 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
500 int secret; | 512 int secret; |
501 do { // Guarantee we get a non-zero value. | 513 do { // Guarantee we get a non-zero value. |
502 secret = base::RandInt(0, std::numeric_limits<int>::max()); | 514 secret = base::RandInt(0, std::numeric_limits<int>::max()); |
503 } while (secret == 0); | 515 } while (secret == 0); |
504 | 516 |
505 id.append(GenerateUniqueRandomChannelID()); | 517 id.append(GenerateUniqueRandomChannelID()); |
506 return id.append(base::StringPrintf("\\%d", secret)); | 518 return id.append(base::StringPrintf("\\%d", secret)); |
507 } | 519 } |
508 | 520 |
509 } // namespace IPC | 521 } // namespace IPC |
OLD | NEW |