diff options
-rw-r--r-- | ipc/file_descriptor_set_posix.cc | 10 | ||||
-rw-r--r-- | ipc/file_descriptor_set_posix.h | 4 | ||||
-rw-r--r-- | ipc/file_descriptor_set_posix_unittest.cc | 6 | ||||
-rw-r--r-- | ipc/ipc_channel.h | 12 | ||||
-rw-r--r-- | ipc/ipc_channel_posix.cc | 11 | ||||
-rw-r--r-- | ipc/ipc_channel_posix.h | 13 |
6 files changed, 24 insertions, 32 deletions
diff --git a/ipc/file_descriptor_set_posix.cc b/ipc/file_descriptor_set_posix.cc index 7f17322..df2a8e4 100644 --- a/ipc/file_descriptor_set_posix.cc +++ b/ipc/file_descriptor_set_posix.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -36,7 +36,7 @@ FileDescriptorSet::~FileDescriptorSet() { } bool FileDescriptorSet::Add(int fd) { - if (descriptors_.size() == MAX_DESCRIPTORS_PER_MESSAGE) + if (descriptors_.size() == kMaxDescriptorsPerMessage) return false; struct base::FileDescriptor sd; @@ -47,14 +47,14 @@ bool FileDescriptorSet::Add(int fd) { } bool FileDescriptorSet::AddAndAutoClose(int fd) { - if (descriptors_.size() == MAX_DESCRIPTORS_PER_MESSAGE) + if (descriptors_.size() == kMaxDescriptorsPerMessage) return false; struct base::FileDescriptor sd; sd.fd = fd; sd.auto_close = true; descriptors_.push_back(sd); - DCHECK(descriptors_.size() <= MAX_DESCRIPTORS_PER_MESSAGE); + DCHECK(descriptors_.size() <= kMaxDescriptorsPerMessage); return true; } @@ -122,7 +122,7 @@ void FileDescriptorSet::CommitAll() { } void FileDescriptorSet::SetDescriptors(const int* buffer, unsigned count) { - DCHECK_LE(count, MAX_DESCRIPTORS_PER_MESSAGE); + DCHECK(count <= kMaxDescriptorsPerMessage); DCHECK_EQ(descriptors_.size(), 0u); DCHECK_EQ(consumed_descriptor_highwater_, 0u); diff --git a/ipc/file_descriptor_set_posix.h b/ipc/file_descriptor_set_posix.h index 1554c38..f7d4ad0 100644 --- a/ipc/file_descriptor_set_posix.h +++ b/ipc/file_descriptor_set_posix.h @@ -31,9 +31,7 @@ class IPC_EXPORT FileDescriptorSet // // In debugging mode, it's a fatal error to try and add more than this number // of descriptors to a FileDescriptorSet. - enum { - MAX_DESCRIPTORS_PER_MESSAGE = 5, - }; + static const size_t kMaxDescriptorsPerMessage = 5; // --------------------------------------------------------------------------- // Interfaces for building during message serialisation... diff --git a/ipc/file_descriptor_set_posix_unittest.cc b/ipc/file_descriptor_set_posix_unittest.cc index 5fc8c50..fdb00f51 100644 --- a/ipc/file_descriptor_set_posix_unittest.cc +++ b/ipc/file_descriptor_set_posix_unittest.cc @@ -1,4 +1,4 @@ -// Copyright (c) 2006-2009 The Chromium Authors. All rights reserved. +// Copyright (c) 2011 The Chromium Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. @@ -67,10 +67,8 @@ TEST(FileDescriptorSet, BasicAddAndClose) { TEST(FileDescriptorSet, MaxSize) { scoped_refptr<FileDescriptorSet> set(new FileDescriptorSet); - for (unsigned i = 0; - i < FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE; ++i) { + for (size_t i = 0; i < FileDescriptorSet::kMaxDescriptorsPerMessage; ++i) ASSERT_TRUE(set->Add(kFDBase + 1 + i)); - } ASSERT_TRUE(!set->Add(kFDBase)); diff --git a/ipc/ipc_channel.h b/ipc/ipc_channel.h index 3724e56..8bb35c4 100644 --- a/ipc/ipc_channel.h +++ b/ipc/ipc_channel.h @@ -94,14 +94,12 @@ class IPC_EXPORT Channel : public Message::Sender { #endif }; - enum { - // The maximum message size in bytes. Attempting to receive a - // message of this size or bigger results in a channel error. - kMaximumMessageSize = 128 * 1024 * 1024, + // The maximum message size in bytes. Attempting to receive a message of this + // size or bigger results in a channel error. + static const size_t kMaximumMessageSize = 128 * 1024 * 1024; - // Ammount of data to read at once from the pipe. - kReadBufferSize = 4 * 1024 - }; + // Ammount of data to read at once from the pipe. + static const size_t kReadBufferSize = 4 * 1024; // Initialize a Channel. // diff --git a/ipc/ipc_channel_posix.cc b/ipc/ipc_channel_posix.cc index df927d0..a88506c 100644 --- a/ipc/ipc_channel_posix.cc +++ b/ipc/ipc_channel_posix.cc @@ -585,8 +585,7 @@ bool Channel::ChannelImpl::ProcessIncomingMessages() { p = input_buf_; end = p + bytes_read; } else { - if (input_overflow_buf_.size() > - static_cast<size_t>(kMaximumMessageSize - bytes_read)) { + if (input_overflow_buf_.size() > (kMaximumMessageSize - bytes_read)) { input_overflow_buf_.clear(); LOG(ERROR) << "IPC message is too big"; return false; @@ -676,7 +675,7 @@ bool Channel::ChannelImpl::ProcessIncomingMessages() { } if (header_fds > - FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE) { + FileDescriptorSet::kMaxDescriptorsPerMessage) { // There are too many descriptors in this message error = "Message requires an excessive number of descriptors"; } @@ -782,7 +781,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() { msgh.msg_iov = &iov; msgh.msg_iovlen = 1; char buf[CMSG_SPACE( - sizeof(int[FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE]))]; + sizeof(int) * FileDescriptorSet::kMaxDescriptorsPerMessage)]; ssize_t bytes_written = 1; int fd_written = -1; @@ -793,7 +792,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() { struct cmsghdr *cmsg; const unsigned num_fds = msg->file_descriptor_set()->size(); - DCHECK_LE(num_fds, FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE); + DCHECK(num_fds <= FileDescriptorSet::kMaxDescriptorsPerMessage); if (msg->file_descriptor_set()->ContainsDirectoryDescriptor()) { LOG(FATAL) << "Panic: attempting to transport directory descriptor over" " IPC. Aborting to maintain sandbox isolation."; @@ -815,7 +814,7 @@ bool Channel::ChannelImpl::ProcessOutgoingMessages() { msgh.msg_controllen = cmsg->cmsg_len; // DCHECK_LE above already checks that - // num_fds < MAX_DESCRIPTORS_PER_MESSAGE so no danger of overflow. + // num_fds < kMaxDescriptorsPerMessage so no danger of overflow. msg->header()->num_fds = static_cast<uint16>(num_fds); #if defined(IPC_USES_READWRITE) diff --git a/ipc/ipc_channel_posix.h b/ipc/ipc_channel_posix.h index 399d282..06c545c 100644 --- a/ipc/ipc_channel_posix.h +++ b/ipc/ipc_channel_posix.h @@ -128,19 +128,18 @@ class Channel::ChannelImpl : public MessageLoopForIO::Watcher { // We read from the pipe into this buffer char input_buf_[Channel::kReadBufferSize]; - enum { - // We assume a worst case: kReadBufferSize bytes of messages, where each - // message has no payload and a full complement of descriptors. - MAX_READ_FDS = (Channel::kReadBufferSize / sizeof(IPC::Message::Header)) * - FileDescriptorSet::MAX_DESCRIPTORS_PER_MESSAGE, - }; + // We assume a worst case: kReadBufferSize bytes of messages, where each + // message has no payload and a full complement of descriptors. + static const size_t kMaxReadFDs = + (Channel::kReadBufferSize / sizeof(IPC::Message::Header)) * + FileDescriptorSet::kMaxDescriptorsPerMessage; // This is a control message buffer large enough to hold kMaxReadFDs #if defined(OS_MACOSX) // TODO(agl): OSX appears to have non-constant CMSG macros! char input_cmsg_buf_[1024]; #else - char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * MAX_READ_FDS)]; + char input_cmsg_buf_[CMSG_SPACE(sizeof(int) * kMaxReadFDs)]; #endif // Large messages that span multiple pipe buffers, get built-up using |