OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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_posix.h" | 5 #include "ipc/ipc_channel_posix.h" |
6 | 6 |
7 #include <errno.h> | 7 #include <errno.h> |
8 #include <fcntl.h> | 8 #include <fcntl.h> |
9 #include <stddef.h> | 9 #include <stddef.h> |
10 #include <sys/types.h> | 10 #include <sys/types.h> |
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
331 // 2b) Client side: Pull the pipe out of the GlobalDescriptors set. | 331 // 2b) Client side: Pull the pipe out of the GlobalDescriptors set. |
332 pipe_name_ = channel_id; | 332 pipe_name_ = channel_id; |
333 pipe_ = ChannelNameToFD(pipe_name_); | 333 pipe_ = ChannelNameToFD(pipe_name_); |
334 if (pipe_ < 0) { | 334 if (pipe_ < 0) { |
335 // Initial IPC channel. | 335 // Initial IPC channel. |
336 if (mode == MODE_SERVER) { | 336 if (mode == MODE_SERVER) { |
337 if (!SocketPair(&pipe_, &client_pipe_)) | 337 if (!SocketPair(&pipe_, &client_pipe_)) |
338 return false; | 338 return false; |
339 AddChannelSocket(pipe_name_, client_pipe_); | 339 AddChannelSocket(pipe_name_, client_pipe_); |
340 } else { | 340 } else { |
| 341 // Guard against inappropriate reuse of the initial IPC channel. If |
| 342 // an IPC channel closes and someone attempts to reuse it by name, the |
| 343 // initial channel must not be recycled here. http://crbug.com/26754. |
| 344 static bool used_initial_channel = false; |
| 345 if (used_initial_channel) { |
| 346 LOG(FATAL) << "Denying attempt to reuse initial IPC channel"; |
| 347 return false; |
| 348 } |
| 349 used_initial_channel = true; |
| 350 |
341 pipe_ = Singleton<base::GlobalDescriptors>()->Get(kPrimaryIPCChannel); | 351 pipe_ = Singleton<base::GlobalDescriptors>()->Get(kPrimaryIPCChannel); |
342 } | 352 } |
343 } else { | 353 } else { |
344 waiting_connect_ = mode == MODE_SERVER; | 354 waiting_connect_ = mode == MODE_SERVER; |
345 } | 355 } |
346 } | 356 } |
347 | 357 |
348 // Create the Hello message to be sent when Connect is called | 358 // Create the Hello message to be sent when Connect is called |
349 scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE, | 359 scoped_ptr<Message> msg(new Message(MSG_ROUTING_NONE, |
350 HELLO_MESSAGE_TYPE, | 360 HELLO_MESSAGE_TYPE, |
(...skipping 658 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1009 | 1019 |
1010 bool Channel::Send(Message* message) { | 1020 bool Channel::Send(Message* message) { |
1011 return channel_impl_->Send(message); | 1021 return channel_impl_->Send(message); |
1012 } | 1022 } |
1013 | 1023 |
1014 int Channel::GetClientFileDescriptor() const { | 1024 int Channel::GetClientFileDescriptor() const { |
1015 return channel_impl_->GetClientFileDescriptor(); | 1025 return channel_impl_->GetClientFileDescriptor(); |
1016 } | 1026 } |
1017 | 1027 |
1018 } // namespace IPC | 1028 } // namespace IPC |
OLD | NEW |