| OLD | NEW |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 186 | 186 |
| 187 // Bind the socket. | 187 // Bind the socket. |
| 188 if (bind(fd, reinterpret_cast<const sockaddr*>(&unix_addr), | 188 if (bind(fd, reinterpret_cast<const sockaddr*>(&unix_addr), |
| 189 unix_addr_len) != 0) { | 189 unix_addr_len) != 0) { |
| 190 PLOG(ERROR) << "bind " << pipe_name; | 190 PLOG(ERROR) << "bind " << pipe_name; |
| 191 if (HANDLE_EINTR(close(fd)) < 0) | 191 if (HANDLE_EINTR(close(fd)) < 0) |
| 192 PLOG(ERROR) << "close " << pipe_name; | 192 PLOG(ERROR) << "close " << pipe_name; |
| 193 return false; | 193 return false; |
| 194 } | 194 } |
| 195 | 195 |
| 196 // Adjust the socket permissions. | 196 // Explicitly set file system permissions on socket, mainly as a precaution |
| 197 // for Chrome OS. |
| 198 // Do not rely on these file permissions to provide security - the file is |
| 199 // created during the above bind() call so there is still a window for |
| 200 // malicious abuse because the file exists between bind() and chmod(). Also, |
| 201 // the file permissions may not be enforced for unix sockets on all platforms. |
| 197 if (chmod(pipe_name.c_str(), 0600)) { | 202 if (chmod(pipe_name.c_str(), 0600)) { |
| 198 PLOG(ERROR) << "fchmod " << pipe_name; | 203 PLOG(ERROR) << "chmod " << pipe_name; |
| 199 if (HANDLE_EINTR(close(fd)) < 0) | 204 if (HANDLE_EINTR(close(fd)) < 0) |
| 200 PLOG(ERROR) << "close " << pipe_name; | 205 PLOG(ERROR) << "close " << pipe_name; |
| 201 return false; | 206 return false; |
| 202 } | 207 } |
| 203 | 208 |
| 204 // Start listening on the socket. | 209 // Start listening on the socket. |
| 205 const int listen_queue_length = 1; | 210 const int listen_queue_length = 1; |
| 206 if (listen(fd, listen_queue_length) != 0) { | 211 if (listen(fd, listen_queue_length) != 0) { |
| 207 PLOG(ERROR) << "listen " << pipe_name; | 212 PLOG(ERROR) << "listen " << pipe_name; |
| 208 if (HANDLE_EINTR(close(fd)) < 0) | 213 if (HANDLE_EINTR(close(fd)) < 0) |
| (...skipping 939 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1148 | 1153 |
| 1149 bool Channel::HasAcceptedConnection() const { | 1154 bool Channel::HasAcceptedConnection() const { |
| 1150 return channel_impl_->HasAcceptedConnection(); | 1155 return channel_impl_->HasAcceptedConnection(); |
| 1151 } | 1156 } |
| 1152 | 1157 |
| 1153 void Channel::ResetToAcceptingConnectionState() { | 1158 void Channel::ResetToAcceptingConnectionState() { |
| 1154 channel_impl_->ResetToAcceptingConnectionState(); | 1159 channel_impl_->ResetToAcceptingConnectionState(); |
| 1155 } | 1160 } |
| 1156 | 1161 |
| 1157 } // namespace IPC | 1162 } // namespace IPC |
| OLD | NEW |