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 |
(...skipping 164 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 *actual_size = sizeof(SerializedDataPipeProducerDispatcher); | 175 *actual_size = sizeof(SerializedDataPipeProducerDispatcher); |
176 return true; | 176 return true; |
177 } | 177 } |
178 | 178 |
179 // Case 2: The consumer isn't closed. We'll replace ourselves with a | 179 // Case 2: The consumer isn't closed. We'll replace ourselves with a |
180 // |RemoteProducerDataPipeImpl|. | 180 // |RemoteProducerDataPipeImpl|. |
181 | 181 |
182 s->consumer_num_bytes = current_num_bytes_; | 182 s->consumer_num_bytes = current_num_bytes_; |
183 // Note: We don't use |port|. | 183 // Note: We don't use |port|. |
184 RefPtr<ChannelEndpoint> channel_endpoint = | 184 RefPtr<ChannelEndpoint> channel_endpoint = |
185 channel->SerializeEndpointWithLocalPeer(destination_for_endpoint, nullptr, | 185 channel->SerializeEndpointWithLocalPeer( |
186 channel_endpoint_client(), 0); | 186 destination_for_endpoint, nullptr, |
| 187 RefPtr<ChannelEndpointClient>(channel_endpoint_client()), 0); |
187 // Note: Keep |*this| alive until the end of this method, to make things | 188 // Note: Keep |*this| alive until the end of this method, to make things |
188 // slightly easier on ourselves. | 189 // slightly easier on ourselves. |
189 std::unique_ptr<DataPipeImpl> self( | 190 std::unique_ptr<DataPipeImpl> self( |
190 ReplaceImpl(util::MakeUnique<RemoteProducerDataPipeImpl>( | 191 ReplaceImpl(util::MakeUnique<RemoteProducerDataPipeImpl>( |
191 std::move(channel_endpoint), std::move(buffer_), start_index_, | 192 std::move(channel_endpoint), std::move(buffer_), start_index_, |
192 current_num_bytes_))); | 193 current_num_bytes_))); |
193 | 194 |
194 *actual_size = sizeof(SerializedDataPipeProducerDispatcher) + | 195 *actual_size = sizeof(SerializedDataPipeProducerDispatcher) + |
195 channel->GetSerializedEndpointSize(); | 196 channel->GetSerializedEndpointSize(); |
196 return true; | 197 return true; |
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
353 *actual_size = sizeof(SerializedDataPipeConsumerDispatcher) + | 354 *actual_size = sizeof(SerializedDataPipeConsumerDispatcher) + |
354 channel->GetSerializedEndpointSize(); | 355 channel->GetSerializedEndpointSize(); |
355 return true; | 356 return true; |
356 } | 357 } |
357 | 358 |
358 // Case 2: The producer isn't closed. We'll replace ourselves with a | 359 // Case 2: The producer isn't closed. We'll replace ourselves with a |
359 // |RemoteConsumerDataPipeImpl|. | 360 // |RemoteConsumerDataPipeImpl|. |
360 | 361 |
361 // Note: We don't use |port|. | 362 // Note: We don't use |port|. |
362 RefPtr<ChannelEndpoint> channel_endpoint = | 363 RefPtr<ChannelEndpoint> channel_endpoint = |
363 channel->SerializeEndpointWithLocalPeer(destination_for_endpoint, | 364 channel->SerializeEndpointWithLocalPeer( |
364 &message_queue, | 365 destination_for_endpoint, &message_queue, |
365 channel_endpoint_client(), 0); | 366 RefPtr<ChannelEndpointClient>(channel_endpoint_client()), 0); |
366 // Note: Keep |*this| alive until the end of this method, to make things | 367 // Note: Keep |*this| alive until the end of this method, to make things |
367 // slightly easier on ourselves. | 368 // slightly easier on ourselves. |
368 std::unique_ptr<DataPipeImpl> self( | 369 std::unique_ptr<DataPipeImpl> self( |
369 ReplaceImpl(util::MakeUnique<RemoteConsumerDataPipeImpl>( | 370 ReplaceImpl(util::MakeUnique<RemoteConsumerDataPipeImpl>( |
370 std::move(channel_endpoint), old_num_bytes, std::move(buffer_), | 371 std::move(channel_endpoint), old_num_bytes, std::move(buffer_), |
371 start_index_))); | 372 start_index_))); |
372 DestroyBuffer(); | 373 DestroyBuffer(); |
373 | 374 |
374 *actual_size = sizeof(SerializedDataPipeConsumerDispatcher) + | 375 *actual_size = sizeof(SerializedDataPipeConsumerDispatcher) + |
375 channel->GetSerializedEndpointSize(); | 376 channel->GetSerializedEndpointSize(); |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
427 | 428 |
428 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) { | 429 void LocalDataPipeImpl::MarkDataAsConsumed(size_t num_bytes) { |
429 DCHECK_LE(num_bytes, current_num_bytes_); | 430 DCHECK_LE(num_bytes, current_num_bytes_); |
430 start_index_ += num_bytes; | 431 start_index_ += num_bytes; |
431 start_index_ %= capacity_num_bytes(); | 432 start_index_ %= capacity_num_bytes(); |
432 current_num_bytes_ -= num_bytes; | 433 current_num_bytes_ -= num_bytes; |
433 } | 434 } |
434 | 435 |
435 } // namespace system | 436 } // namespace system |
436 } // namespace mojo | 437 } // namespace mojo |
OLD | NEW |