From 502bd4a3d1a1cf0d4ec2c2d827364164797b5bf8 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Tue, 26 Jan 2010 18:13:43 -0600 Subject: [PATCH] IPC socketpair()s should be CLOEXEC (dup2() unsets the flag for the new fd in the child process). irc-r=bsmedberg --- .../src/chrome/common/ipc_channel_posix.cc | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/ipc/chromium/src/chrome/common/ipc_channel_posix.cc b/ipc/chromium/src/chrome/common/ipc_channel_posix.cc index 92040dfc7f30..3b6120e9a317 100644 --- a/ipc/chromium/src/chrome/common/ipc_channel_posix.cc +++ b/ipc/chromium/src/chrome/common/ipc_channel_posix.cc @@ -238,6 +238,20 @@ bool ClientConnectToFifo(const std::string &pipe_name, int* client_socket) { return true; } +#if defined(CHROMIUM_MOZILLA_BUILD) +bool SetCloseOnExec(int fd) { + int flags = fcntl(fd, F_GETFD); + if (flags == -1) + return false; + + flags |= FD_CLOEXEC; + if (fcntl(fd, F_SETFD, flags) == -1) + return false; + + return true; +} +#endif + } // namespace //------------------------------------------------------------------------------ @@ -298,6 +312,16 @@ bool Channel::ChannelImpl::CreatePipe(const std::wstring& channel_id, HANDLE_EINTR(close(pipe_fds[1])); return false; } + +#if defined(CHROMIUM_MOZILLA_BUILD) + if (!SetCloseOnExec(pipe_fds[0]) || + !SetCloseOnExec(pipe_fds[1])) { + HANDLE_EINTR(close(pipe_fds[0])); + HANDLE_EINTR(close(pipe_fds[1])); + return false; + } +#endif + pipe_ = pipe_fds[0]; client_pipe_ = pipe_fds[1];