| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 // TODO(vtl): I currently potentially overflow in doing index calculations. | 5 // TODO(vtl): I currently potentially overflow in doing index calculations. |
| 6 // E.g., |start_index_| and |current_num_bytes_| fit into a |uint32_t|, but | 6 // E.g., |start_index_| and |current_num_bytes_| fit into a |uint32_t|, but |
| 7 // their sum may not. This is bad and poses a security risk. (We're currently | 7 // their sum may not. This is bad and poses a security risk. (We're currently |
| 8 // saved by the limit on capacity -- the maximum size of the buffer, checked in | 8 // saved by the limit on capacity -- the maximum size of the buffer, checked in |
| 9 // |DataPipe::ValidateOptions()|, is currently sufficiently small.) | 9 // |DataPipe::ValidateOptions()|, is currently sufficiently small.) |
| 10 | 10 |
| 11 #include "mojo/edk/system/local_data_pipe_impl.h" | 11 #include "mojo/edk/system/local_data_pipe_impl.h" |
| 12 | 12 |
| 13 #include <string.h> | 13 #include <string.h> |
| 14 | 14 |
| 15 #include <algorithm> | 15 #include <algorithm> |
| 16 #include <utility> | 16 #include <utility> |
| 17 | 17 |
| 18 #include "base/logging.h" | 18 #include "base/logging.h" |
| 19 #include "mojo/edk/system/channel.h" | 19 #include "mojo/edk/system/channel.h" |
| 20 #include "mojo/edk/system/configuration.h" | 20 #include "mojo/edk/system/configuration.h" |
| 21 #include "mojo/edk/system/data_pipe.h" | 21 #include "mojo/edk/system/data_pipe.h" |
| 22 #include "mojo/edk/system/message_in_transit.h" | 22 #include "mojo/edk/system/message_in_transit.h" |
| 23 #include "mojo/edk/system/message_in_transit_queue.h" | 23 #include "mojo/edk/system/message_in_transit_queue.h" |
| 24 #include "mojo/edk/system/remote_consumer_data_pipe_impl.h" | 24 #include "mojo/edk/system/remote_consumer_data_pipe_impl.h" |
| 25 #include "mojo/edk/system/remote_producer_data_pipe_impl.h" | 25 #include "mojo/edk/system/remote_producer_data_pipe_impl.h" |
| 26 #include "mojo/edk/util/make_unique.h" | 26 #include "mojo/edk/util/make_unique.h" |
| 27 | 27 |
| 28 using mojo::embedder::ScopedPlatformHandle; |
| 28 using mojo::util::RefPtr; | 29 using mojo::util::RefPtr; |
| 29 | 30 |
| 30 namespace mojo { | 31 namespace mojo { |
| 31 namespace system { | 32 namespace system { |
| 32 | 33 |
| 33 // Assert some things about some things defined in data_pipe_impl.h (don't make | 34 // Assert some things about some things defined in data_pipe_impl.h (don't make |
| 34 // the assertions there, to avoid including message_in_transit.h). | 35 // the assertions there, to avoid including message_in_transit.h). |
| 35 static_assert(MOJO_ALIGNOF(SerializedDataPipeConsumerDispatcher) == | 36 static_assert(MOJO_ALIGNOF(SerializedDataPipeConsumerDispatcher) == |
| 36 MessageInTransit::kMessageAlignment, | 37 MessageInTransit::kMessageAlignment, |
| 37 "Wrong alignment"); | 38 "Wrong alignment"); |
| (...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 157 size_t* max_platform_handles) { | 158 size_t* max_platform_handles) { |
| 158 *max_size = sizeof(SerializedDataPipeProducerDispatcher) + | 159 *max_size = sizeof(SerializedDataPipeProducerDispatcher) + |
| 159 channel->GetSerializedEndpointSize(); | 160 channel->GetSerializedEndpointSize(); |
| 160 *max_platform_handles = 0; | 161 *max_platform_handles = 0; |
| 161 } | 162 } |
| 162 | 163 |
| 163 bool LocalDataPipeImpl::ProducerEndSerialize( | 164 bool LocalDataPipeImpl::ProducerEndSerialize( |
| 164 Channel* channel, | 165 Channel* channel, |
| 165 void* destination, | 166 void* destination, |
| 166 size_t* actual_size, | 167 size_t* actual_size, |
| 167 embedder::PlatformHandleVector* platform_handles) { | 168 std::vector<ScopedPlatformHandle>* /*platform_handles*/) { |
| 168 SerializedDataPipeProducerDispatcher* s = | 169 SerializedDataPipeProducerDispatcher* s = |
| 169 static_cast<SerializedDataPipeProducerDispatcher*>(destination); | 170 static_cast<SerializedDataPipeProducerDispatcher*>(destination); |
| 170 s->validated_options = validated_options(); | 171 s->validated_options = validated_options(); |
| 171 void* destination_for_endpoint = static_cast<char*>(destination) + | 172 void* destination_for_endpoint = static_cast<char*>(destination) + |
| 172 sizeof(SerializedDataPipeProducerDispatcher); | 173 sizeof(SerializedDataPipeProducerDispatcher); |
| 173 | 174 |
| 174 if (!consumer_open()) { | 175 if (!consumer_open()) { |
| 175 // Case 1: The consumer is closed. | 176 // Case 1: The consumer is closed. |
| 176 s->consumer_num_bytes = static_cast<size_t>(-1); | 177 s->consumer_num_bytes = static_cast<size_t>(-1); |
| 177 *actual_size = sizeof(SerializedDataPipeProducerDispatcher); | 178 *actual_size = sizeof(SerializedDataPipeProducerDispatcher); |
| (...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 size_t* max_platform_handles) { | 330 size_t* max_platform_handles) { |
| 330 *max_size = sizeof(SerializedDataPipeConsumerDispatcher) + | 331 *max_size = sizeof(SerializedDataPipeConsumerDispatcher) + |
| 331 channel->GetSerializedEndpointSize(); | 332 channel->GetSerializedEndpointSize(); |
| 332 *max_platform_handles = 0; | 333 *max_platform_handles = 0; |
| 333 } | 334 } |
| 334 | 335 |
| 335 bool LocalDataPipeImpl::ConsumerEndSerialize( | 336 bool LocalDataPipeImpl::ConsumerEndSerialize( |
| 336 Channel* channel, | 337 Channel* channel, |
| 337 void* destination, | 338 void* destination, |
| 338 size_t* actual_size, | 339 size_t* actual_size, |
| 339 embedder::PlatformHandleVector* platform_handles) { | 340 std::vector<ScopedPlatformHandle>* /*platform_handles*/) { |
| 340 SerializedDataPipeConsumerDispatcher* s = | 341 SerializedDataPipeConsumerDispatcher* s = |
| 341 static_cast<SerializedDataPipeConsumerDispatcher*>(destination); | 342 static_cast<SerializedDataPipeConsumerDispatcher*>(destination); |
| 342 s->validated_options = validated_options(); | 343 s->validated_options = validated_options(); |
| 343 void* destination_for_endpoint = static_cast<char*>(destination) + | 344 void* destination_for_endpoint = static_cast<char*>(destination) + |
| 344 sizeof(SerializedDataPipeConsumerDispatcher); | 345 sizeof(SerializedDataPipeConsumerDispatcher); |
| 345 | 346 |
| 346 size_t old_num_bytes = current_num_bytes_; | 347 size_t old_num_bytes = current_num_bytes_; |
| 347 MessageInTransitQueue message_queue; | 348 MessageInTransitQueue message_queue; |
| 348 ConvertDataToMessages(buffer_.get(), &start_index_, ¤t_num_bytes_, | 349 ConvertDataToMessages(buffer_.get(), &start_index_, ¤t_num_bytes_, |
| 349 &message_queue); | 350 &message_queue); |
| (...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 430 | 431 |
| 431 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) { | 432 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) { |
| 432 DCHECK_LE(num_bytes, current_num_bytes_); | 433 DCHECK_LE(num_bytes, current_num_bytes_); |
| 433 start_index_ += num_bytes; | 434 start_index_ += num_bytes; |
| 434 start_index_ %= capacity_num_bytes(); | 435 start_index_ %= capacity_num_bytes(); |
| 435 current_num_bytes_ -= num_bytes; | 436 current_num_bytes_ -= num_bytes; |
| 436 } | 437 } |
| 437 | 438 |
| 438 } // namespace system | 439 } // namespace system |
| 439 } // namespace mojo | 440 } // namespace mojo |
| OLD | NEW |