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

Side by Side Diff: ipc/ipc_channel_posix.cc

Issue 1120343002: Make IPC::Channel buffers stack based and secure against growth (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Optimistic! 8 KB will work. Created 5 years, 7 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
« ipc/ipc_channel_posix.h ('K') | « ipc/ipc_channel_posix.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 (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_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/socket.h> 10 #include <sys/socket.h>
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 Mode mode, Listener* listener) 185 Mode mode, Listener* listener)
186 : ChannelReader(listener), 186 : ChannelReader(listener),
187 mode_(mode), 187 mode_(mode),
188 peer_pid_(base::kNullProcessId), 188 peer_pid_(base::kNullProcessId),
189 is_blocked_on_write_(false), 189 is_blocked_on_write_(false),
190 waiting_connect_(true), 190 waiting_connect_(true),
191 message_send_bytes_written_(0), 191 message_send_bytes_written_(0),
192 pipe_name_(channel_handle.name), 192 pipe_name_(channel_handle.name),
193 in_dtor_(false), 193 in_dtor_(false),
194 must_unlink_(false) { 194 must_unlink_(false) {
195 memset(input_cmsg_buf_, 0, sizeof(input_cmsg_buf_));
196 if (!CreatePipe(channel_handle)) { 195 if (!CreatePipe(channel_handle)) {
197 // The pipe may have been closed already. 196 // The pipe may have been closed already.
198 const char *modestr = (mode_ & MODE_SERVER_FLAG) ? "server" : "client"; 197 const char *modestr = (mode_ & MODE_SERVER_FLAG) ? "server" : "client";
199 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name 198 LOG(WARNING) << "Unable to create pipe named \"" << channel_handle.name
200 << "\" in " << modestr << " mode"; 199 << "\" in " << modestr << " mode";
201 } 200 }
202 } 201 }
203 202
204 ChannelPosix::~ChannelPosix() { 203 ChannelPosix::~ChannelPosix() {
205 in_dtor_ = true; 204 in_dtor_ = true;
(...skipping 611 matching lines...) Expand 10 before | Expand all | Expand 10 after
817 int* bytes_read) { 816 int* bytes_read) {
818 if (!pipe_.is_valid()) 817 if (!pipe_.is_valid())
819 return READ_FAILED; 818 return READ_FAILED;
820 819
821 struct msghdr msg = {0}; 820 struct msghdr msg = {0};
822 821
823 struct iovec iov = {buffer, static_cast<size_t>(buffer_len)}; 822 struct iovec iov = {buffer, static_cast<size_t>(buffer_len)};
824 msg.msg_iov = &iov; 823 msg.msg_iov = &iov;
825 msg.msg_iovlen = 1; 824 msg.msg_iovlen = 1;
826 825
827 msg.msg_control = input_cmsg_buf_; 826 char input_cmsg_buf[kMaxReadFDBuffer];
827 msg.msg_control = input_cmsg_buf;
828 828
829 // recvmsg() returns 0 if the connection has closed or EAGAIN if no data 829 // recvmsg() returns 0 if the connection has closed or EAGAIN if no data
830 // is waiting on the pipe. 830 // is waiting on the pipe.
831 #if defined(IPC_USES_READWRITE) 831 #if defined(IPC_USES_READWRITE)
832 if (fd_pipe_.is_valid()) { 832 if (fd_pipe_.is_valid()) {
833 *bytes_read = HANDLE_EINTR(read(pipe_.get(), buffer, buffer_len)); 833 *bytes_read = HANDLE_EINTR(read(pipe_.get(), buffer, buffer_len));
834 msg.msg_controllen = 0; 834 msg.msg_controllen = 0;
835 } else 835 } else
836 #endif // IPC_USES_READWRITE 836 #endif // IPC_USES_READWRITE
837 { 837 {
838 msg.msg_controllen = sizeof(input_cmsg_buf_); 838 msg.msg_controllen = sizeof(input_cmsg_buf);
839 *bytes_read = HANDLE_EINTR(recvmsg(pipe_.get(), &msg, MSG_DONTWAIT)); 839 *bytes_read = HANDLE_EINTR(recvmsg(pipe_.get(), &msg, MSG_DONTWAIT));
840 } 840 }
841 if (*bytes_read < 0) { 841 if (*bytes_read < 0) {
842 if (errno == EAGAIN) { 842 if (errno == EAGAIN) {
843 return READ_PENDING; 843 return READ_PENDING;
844 #if defined(OS_MACOSX) 844 #if defined(OS_MACOSX)
845 } else if (errno == EPERM) { 845 } else if (errno == EPERM) {
846 // On OSX, reading from a pipe with no listener returns EPERM 846 // On OSX, reading from a pipe with no listener returns EPERM
847 // treat this as a special case to prevent spurious error messages 847 // treat this as a special case to prevent spurious error messages
848 // to the console. 848 // to the console.
(...skipping 20 matching lines...) Expand all
869 } 869 }
870 870
871 #if defined(IPC_USES_READWRITE) 871 #if defined(IPC_USES_READWRITE)
872 bool ChannelPosix::ReadFileDescriptorsFromFDPipe() { 872 bool ChannelPosix::ReadFileDescriptorsFromFDPipe() {
873 char dummy; 873 char dummy;
874 struct iovec fd_pipe_iov = { &dummy, 1 }; 874 struct iovec fd_pipe_iov = { &dummy, 1 };
875 875
876 struct msghdr msg = { 0 }; 876 struct msghdr msg = { 0 };
877 msg.msg_iov = &fd_pipe_iov; 877 msg.msg_iov = &fd_pipe_iov;
878 msg.msg_iovlen = 1; 878 msg.msg_iovlen = 1;
879 msg.msg_control = input_cmsg_buf_; 879 char input_cmsg_buf[kMaxReadFDBuffer];
880 msg.msg_controllen = sizeof(input_cmsg_buf_); 880 msg.msg_control = input_cmsg_buf;
881 msg.msg_controllen = sizeof(input_cmsg_buf);
881 ssize_t bytes_received = 882 ssize_t bytes_received =
882 HANDLE_EINTR(recvmsg(fd_pipe_.get(), &msg, MSG_DONTWAIT)); 883 HANDLE_EINTR(recvmsg(fd_pipe_.get(), &msg, MSG_DONTWAIT));
883 884
884 if (bytes_received != 1) 885 if (bytes_received != 1)
885 return true; // No message waiting. 886 return true; // No message waiting.
886 887
887 if (!ExtractFileDescriptorsFromMsghdr(&msg)) 888 if (!ExtractFileDescriptorsFromMsghdr(&msg))
888 return false; 889 return false;
889 return true; 890 return true;
890 } 891 }
(...skipping 245 matching lines...) Expand 10 before | Expand all | Expand 10 after
1136 } 1137 }
1137 1138
1138 #if defined(OS_LINUX) 1139 #if defined(OS_LINUX)
1139 // static 1140 // static
1140 void Channel::SetGlobalPid(int pid) { 1141 void Channel::SetGlobalPid(int pid) {
1141 ChannelPosix::SetGlobalPid(pid); 1142 ChannelPosix::SetGlobalPid(pid);
1142 } 1143 }
1143 #endif // OS_LINUX 1144 #endif // OS_LINUX
1144 1145
1145 } // namespace IPC 1146 } // namespace IPC
OLDNEW
« ipc/ipc_channel_posix.h ('K') | « ipc/ipc_channel_posix.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698