diff options
author | lhchavez <lhchavez@chromium.org> | 2016-01-08 16:47:54 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-01-09 00:49:12 +0000 |
commit | 41bc841af01d297a6d337a62a195cd4080dc7639 (patch) | |
tree | f5723e7e53f58ce707d655329753787d441064dc | |
parent | 7e642027bde0962b5ff5ee85fe6b3cd61fef7fd5 (diff) | |
download | chromium_src-41bc841af01d297a6d337a62a195cd4080dc7639.zip chromium_src-41bc841af01d297a6d337a62a195cd4080dc7639.tar.gz chromium_src-41bc841af01d297a6d337a62a195cd4080dc7639.tar.bz2 |
mojo: Fix the size of several platform-specific structs
Having SerializedPlatformHandleDispatcher::platform_handle_index (and
other platform-specific structs) be a size_t causes 64-bit processes
communicating with 32-bit processes to fail the size check. This change
fixes the size of |platform_handle_index| (and similar ones) so it is
fixed across platforms (to uint32_t) so that the error goes away.
BUG=574945
TEST=32-bit ARC communication works in 64-bit Chrome OS
Review URL: https://codereview.chromium.org/1568693002
Cr-Commit-Position: refs/heads/master@{#368488}
10 files changed, 95 insertions, 46 deletions
diff --git a/mojo/edk/system/data_pipe.cc b/mojo/edk/system/data_pipe.cc index 3f53798..54a6df4 100644 --- a/mojo/edk/system/data_pipe.cc +++ b/mojo/edk/system/data_pipe.cc @@ -8,6 +8,9 @@ #include <stdint.h> #include <string.h> +#include <algorithm> +#include <limits> + #include "mojo/edk/system/configuration.h" #include "mojo/edk/system/options_validation.h" #include "mojo/edk/system/raw_channel.h" @@ -18,17 +21,17 @@ namespace edk { namespace { -const size_t kInvalidDataPipeHandleIndex = static_cast<size_t>(-1); +const uint32_t kInvalidDataPipeHandleIndex = static_cast<uint32_t>(-1); struct MOJO_ALIGNAS(8) SerializedDataPipeHandleDispatcher { - size_t platform_handle_index; // (Or |kInvalidDataPipeHandleIndex|.) + uint32_t platform_handle_index; // (Or |kInvalidDataPipeHandleIndex|.) // These are from MojoCreateDataPipeOptions MojoCreateDataPipeOptionsFlags flags; uint32_t element_num_bytes; uint32_t capacity_num_bytes; - size_t shared_memory_handle_index; // (Or |kInvalidDataPipeHandleIndex|.) + uint32_t shared_memory_handle_index; // (Or |kInvalidDataPipeHandleIndex|.) uint32_t shared_memory_size; }; @@ -119,7 +122,9 @@ void DataPipe::EndSerialize(const MojoCreateDataPipeOptions& options, SerializedDataPipeHandleDispatcher* serialization = static_cast<SerializedDataPipeHandleDispatcher*>(destination); if (channel_handle.is_valid()) { - serialization->platform_handle_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->platform_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(channel_handle.release()); } else { serialization->platform_handle_index = kInvalidDataPipeHandleIndex; @@ -131,7 +136,9 @@ void DataPipe::EndSerialize(const MojoCreateDataPipeOptions& options, serialization->shared_memory_size = static_cast<uint32_t>(shared_memory_size); if (serialization->shared_memory_size) { - serialization->shared_memory_handle_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->shared_memory_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(shared_memory_handle.release()); } else { serialization->shared_memory_handle_index = kInvalidDataPipeHandleIndex; diff --git a/mojo/edk/system/message_pipe_dispatcher.cc b/mojo/edk/system/message_pipe_dispatcher.cc index 11dc586..b35e9cd 100644 --- a/mojo/edk/system/message_pipe_dispatcher.cc +++ b/mojo/edk/system/message_pipe_dispatcher.cc @@ -7,7 +7,9 @@ #include <stddef.h> #include <stdint.h> +#include <limits> #include <utility> +#include <vector> #include "base/bind.h" #include "base/debug/stack_trace.h" @@ -28,7 +30,7 @@ namespace edk { namespace { -const size_t kInvalidMessagePipeHandleIndex = static_cast<size_t>(-1); +const uint32_t kInvalidMessagePipeHandleIndex = static_cast<uint32_t>(-1); struct MOJO_ALIGNAS(8) SerializedMessagePipeHandleDispatcher { bool transferable; @@ -37,21 +39,22 @@ struct MOJO_ALIGNAS(8) SerializedMessagePipeHandleDispatcher { // The following members are only set if transferable is true. // Could be |kInvalidMessagePipeHandleIndex| if the other endpoint of the MP // was closed. - size_t platform_handle_index; + uint32_t platform_handle_index; - size_t shared_memory_handle_index; // (Or |kInvalidMessagePipeHandleIndex|.) + uint32_t + shared_memory_handle_index; // (Or |kInvalidMessagePipeHandleIndex|.) uint32_t shared_memory_size; - size_t serialized_read_buffer_size; - size_t serialized_write_buffer_size; - size_t serialized_message_queue_size; + uint32_t serialized_read_buffer_size; + uint32_t serialized_write_buffer_size; + uint32_t serialized_message_queue_size; // These are the FDs required as part of serializing channel_ and // message_queue_. This is only used on POSIX. - size_t serialized_fds_index; // (Or |kInvalidMessagePipeHandleIndex|.) - size_t serialized_read_fds_length; - size_t serialized_write_fds_length; - size_t serialized_message_fds_length; + uint32_t serialized_fds_index; // (Or |kInvalidMessagePipeHandleIndex|.) + uint32_t serialized_read_fds_length; + uint32_t serialized_write_fds_length; + uint32_t serialized_message_fds_length; }; char* SerializeBuffer(char* start, std::vector<char>* buffer) { @@ -805,17 +808,26 @@ bool MessagePipeDispatcher::EndSerializeAndCloseImplNoLock( serialization->transferable = transferable_; serialization->pipe_id = pipe_id_; if (serialized_platform_handle_.is_valid()) { - serialization->platform_handle_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->platform_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(serialized_platform_handle_.release()); } else { serialization->platform_handle_index = kInvalidMessagePipeHandleIndex; } serialization->write_error = write_error_; - serialization->serialized_read_buffer_size = serialized_read_buffer_.size(); - serialization->serialized_write_buffer_size = serialized_write_buffer_.size(); + DCHECK(serialized_read_buffer_.size() < std::numeric_limits<uint32_t>::max()); + serialization->serialized_read_buffer_size = + static_cast<uint32_t>(serialized_read_buffer_.size()); + DCHECK(serialized_write_buffer_.size() < + std::numeric_limits<uint32_t>::max()); + serialization->serialized_write_buffer_size = + static_cast<uint32_t>(serialized_write_buffer_.size()); + DCHECK(serialized_message_queue_.size() < + std::numeric_limits<uint32_t>::max()); serialization->serialized_message_queue_size = - serialized_message_queue_.size(); + static_cast<uint32_t>(serialized_message_queue_.size()); serialization->shared_memory_size = static_cast<uint32_t>( serialization->serialized_read_buffer_size + @@ -832,20 +844,30 @@ bool MessagePipeDispatcher::EndSerializeAndCloseImplNoLock( start = SerializeBuffer(start, &serialized_write_buffer_); start = SerializeBuffer(start, &serialized_message_queue_); - serialization->shared_memory_handle_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->shared_memory_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(shared_buffer->PassPlatformHandle().release()); } else { serialization->shared_memory_handle_index = kInvalidMessagePipeHandleIndex; } - serialization->serialized_read_fds_length = serialized_read_fds_length_; - serialization->serialized_write_fds_length = serialized_write_fds_length_; - serialization->serialized_message_fds_length = serialized_message_fds_length_; + DCHECK(serialized_read_fds_length_ < std::numeric_limits<uint32_t>::max()); + serialization->serialized_read_fds_length = + static_cast<uint32_t>(serialized_read_fds_length_); + DCHECK(serialized_write_fds_length_ < std::numeric_limits<uint32_t>::max()); + serialization->serialized_write_fds_length = + static_cast<uint32_t>(serialized_write_fds_length_); + DCHECK(serialized_message_fds_length_ < std::numeric_limits<uint32_t>::max()); + serialization->serialized_message_fds_length = + static_cast<uint32_t>(serialized_message_fds_length_); if (serialized_fds_.empty()) { serialization->serialized_fds_index = kInvalidMessagePipeHandleIndex; } else { #if defined(OS_POSIX) - serialization->serialized_fds_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->serialized_fds_index = + static_cast<uint32_t>(platform_handles->size()); for (size_t i = 0; i < serialized_fds_.size(); ++i) platform_handles->push_back(PlatformHandle(serialized_fds_[i])); serialized_fds_.clear(); diff --git a/mojo/edk/system/platform_handle_dispatcher.cc b/mojo/edk/system/platform_handle_dispatcher.cc index ab0ac12..eadcb8e 100644 --- a/mojo/edk/system/platform_handle_dispatcher.cc +++ b/mojo/edk/system/platform_handle_dispatcher.cc @@ -7,6 +7,7 @@ #include <stddef.h> #include <algorithm> +#include <limits> #include <utility> #include "base/logging.h" @@ -16,10 +17,10 @@ namespace edk { namespace { -const size_t kInvalidPlatformHandleIndex = static_cast<size_t>(-1); +const uint32_t kInvalidPlatformHandleIndex = static_cast<uint32_t>(-1); struct MOJO_ALIGNAS(8) SerializedPlatformHandleDispatcher { - size_t platform_handle_index; // (Or |kInvalidPlatformHandleIndex|.) + uint32_t platform_handle_index; // (Or |kInvalidPlatformHandleIndex|.) }; } // namespace @@ -98,7 +99,9 @@ bool PlatformHandleDispatcher::EndSerializeAndCloseImplNoLock( SerializedPlatformHandleDispatcher* serialization = static_cast<SerializedPlatformHandleDispatcher*>(destination); if (platform_handle_.is_valid()) { - serialization->platform_handle_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->platform_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(platform_handle_.release()); } else { serialization->platform_handle_index = kInvalidPlatformHandleIndex; diff --git a/mojo/edk/system/shared_buffer_dispatcher.cc b/mojo/edk/system/shared_buffer_dispatcher.cc index 0da8bbe..510db85 100644 --- a/mojo/edk/system/shared_buffer_dispatcher.cc +++ b/mojo/edk/system/shared_buffer_dispatcher.cc @@ -7,6 +7,7 @@ #include <stddef.h> #include <stdint.h> +#include <algorithm> #include <limits> #include <utility> @@ -24,8 +25,8 @@ namespace edk { namespace { struct MOJO_ALIGNAS(8) SerializedSharedBufferDispatcher { - size_t num_bytes; - size_t platform_handle_index; + uint32_t num_bytes; + uint32_t platform_handle_index; }; } // namespace @@ -257,8 +258,12 @@ bool SharedBufferDispatcher::EndSerializeAndCloseImplNoLock( return false; } - serialization->num_bytes = shared_buffer_->GetNumBytes(); - serialization->platform_handle_index = platform_handles->size(); + DCHECK(shared_buffer_->GetNumBytes() < std::numeric_limits<uint32_t>::max()); + serialization->num_bytes = + static_cast<uint32_t>(shared_buffer_->GetNumBytes()); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->platform_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(platform_handle.release()); *actual_size = sizeof(SerializedSharedBufferDispatcher); diff --git a/third_party/mojo/src/mojo/edk/system/data_pipe.cc b/third_party/mojo/src/mojo/edk/system/data_pipe.cc index 7ed7e7c92..396a160 100644 --- a/third_party/mojo/src/mojo/edk/system/data_pipe.cc +++ b/third_party/mojo/src/mojo/edk/system/data_pipe.cc @@ -187,7 +187,7 @@ bool DataPipe::ProducerDeserialize(Channel* channel, } if (!consumer_open) { - if (s->consumer_num_bytes != static_cast<size_t>(-1)) { + if (s->consumer_num_bytes != static_cast<uint32_t>(-1)) { LOG(ERROR) << "Invalid serialized data pipe producer (bad consumer_num_bytes)"; return false; diff --git a/third_party/mojo/src/mojo/edk/system/data_pipe_impl.h b/third_party/mojo/src/mojo/edk/system/data_pipe_impl.h index 067feee..391bb34 100644 --- a/third_party/mojo/src/mojo/edk/system/data_pipe_impl.h +++ b/third_party/mojo/src/mojo/edk/system/data_pipe_impl.h @@ -140,9 +140,9 @@ struct MOJO_ALIGNAS(8) SerializedDataPipeProducerDispatcher { // However, the deserializer must revalidate (as with everything received). MojoCreateDataPipeOptions validated_options; // Number of bytes already enqueued to the consumer. Set to - // |static_cast<size_t>(-1)| if the consumer is already closed, in which case - // this will *not* be followed by a serialized |ChannelEndpoint|. - size_t consumer_num_bytes; + // |static_cast<uint32_t>(-1)| if the consumer is already closed, in which + // case this will *not* be followed by a serialized |ChannelEndpoint|. + uint32_t consumer_num_bytes; }; // Serialized form of a consumer dispatcher. This will actually be followed by a diff --git a/third_party/mojo/src/mojo/edk/system/local_data_pipe_impl.cc b/third_party/mojo/src/mojo/edk/system/local_data_pipe_impl.cc index 6dc9f82..415d186 100644 --- a/third_party/mojo/src/mojo/edk/system/local_data_pipe_impl.cc +++ b/third_party/mojo/src/mojo/edk/system/local_data_pipe_impl.cc @@ -12,6 +12,7 @@ #include <string.h> #include <algorithm> +#include <limits> #include <utility> #include "base/logging.h" @@ -170,7 +171,7 @@ bool LocalDataPipeImpl::ProducerEndSerialize( if (!consumer_open()) { // Case 1: The consumer is closed. - s->consumer_num_bytes = static_cast<size_t>(-1); + s->consumer_num_bytes = static_cast<uint32_t>(-1); *actual_size = sizeof(SerializedDataPipeProducerDispatcher); return true; } @@ -178,7 +179,8 @@ bool LocalDataPipeImpl::ProducerEndSerialize( // Case 2: The consumer isn't closed. We'll replace ourselves with a // |RemoteProducerDataPipeImpl|. - s->consumer_num_bytes = current_num_bytes_; + DCHECK(current_num_bytes_ < std::numeric_limits<uint32_t>::max()); + s->consumer_num_bytes = static_cast<uint32_t>(current_num_bytes_); // Note: We don't use |port|. scoped_refptr<ChannelEndpoint> channel_endpoint = channel->SerializeEndpointWithLocalPeer(destination_for_endpoint, nullptr, diff --git a/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.cc b/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.cc index 5e3f639..c67e33e 100644 --- a/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.cc +++ b/third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.cc @@ -5,6 +5,7 @@ #include "third_party/mojo/src/mojo/edk/system/platform_handle_dispatcher.h" #include <algorithm> +#include <limits> #include <utility> #include "base/logging.h" @@ -14,10 +15,10 @@ namespace system { namespace { -const size_t kInvalidPlatformHandleIndex = static_cast<size_t>(-1); +const uint32_t kInvalidPlatformHandleIndex = static_cast<uint32_t>(-1); struct SerializedPlatformHandleDispatcher { - size_t platform_handle_index; // (Or |kInvalidPlatformHandleIndex|.) + uint32_t platform_handle_index; // (Or |kInvalidPlatformHandleIndex|.) }; } // namespace @@ -102,7 +103,9 @@ bool PlatformHandleDispatcher::EndSerializeAndCloseImplNoLock( SerializedPlatformHandleDispatcher* serialization = static_cast<SerializedPlatformHandleDispatcher*>(destination); if (platform_handle_.is_valid()) { - serialization->platform_handle_index = platform_handles->size(); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->platform_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(platform_handle_.release()); } else { serialization->platform_handle_index = kInvalidPlatformHandleIndex; diff --git a/third_party/mojo/src/mojo/edk/system/remote_consumer_data_pipe_impl.cc b/third_party/mojo/src/mojo/edk/system/remote_consumer_data_pipe_impl.cc index 8cb48db..953fae7a 100644 --- a/third_party/mojo/src/mojo/edk/system/remote_consumer_data_pipe_impl.cc +++ b/third_party/mojo/src/mojo/edk/system/remote_consumer_data_pipe_impl.cc @@ -6,6 +6,7 @@ #include <string.h> #include <algorithm> +#include <limits> #include <utility> #include "base/logging.h" @@ -284,7 +285,7 @@ bool RemoteConsumerDataPipeImpl::ProducerEndSerialize( if (!consumer_open()) { // Case 1: The consumer is closed. - s->consumer_num_bytes = static_cast<size_t>(-1); + s->consumer_num_bytes = static_cast<uint32_t>(-1); *actual_size = sizeof(SerializedDataPipeProducerDispatcher); return true; } @@ -292,7 +293,8 @@ bool RemoteConsumerDataPipeImpl::ProducerEndSerialize( // Case 2: The consumer isn't closed. We pass |channel_endpoint| back to the // |Channel|. There's no reason for us to continue to exist afterwards. - s->consumer_num_bytes = consumer_num_bytes_; + DCHECK(consumer_num_bytes_ < std::numeric_limits<uint32_t>::max()); + s->consumer_num_bytes = static_cast<uint32_t>(consumer_num_bytes_); // Note: We don't use |port|. scoped_refptr<ChannelEndpoint> channel_endpoint; channel_endpoint.swap(channel_endpoint_); diff --git a/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc b/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc index 8c64e1a..d31efe4 100644 --- a/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc +++ b/third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.cc @@ -4,6 +4,7 @@ #include "third_party/mojo/src/mojo/edk/system/shared_buffer_dispatcher.h" +#include <algorithm> #include <limits> #include <utility> @@ -22,8 +23,8 @@ namespace system { namespace { struct SerializedSharedBufferDispatcher { - size_t num_bytes; - size_t platform_handle_index; + uint32_t num_bytes; + uint32_t platform_handle_index; }; } // namespace @@ -261,8 +262,12 @@ bool SharedBufferDispatcher::EndSerializeAndCloseImplNoLock( return false; } - serialization->num_bytes = shared_buffer_->GetNumBytes(); - serialization->platform_handle_index = platform_handles->size(); + DCHECK(shared_buffer_->GetNumBytes() < std::numeric_limits<uint32_t>::max()); + serialization->num_bytes = + static_cast<uint32_t>(shared_buffer_->GetNumBytes()); + DCHECK(platform_handles->size() < std::numeric_limits<uint32_t>::max()); + serialization->platform_handle_index = + static_cast<uint32_t>(platform_handles->size()); platform_handles->push_back(platform_handle.release()); *actual_size = sizeof(SerializedSharedBufferDispatcher); |