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 252 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
263 } | 263 } |
264 | 264 |
265 MojoResult LocalDataPipe::ConsumerBeginReadDataImplNoLock( | 265 MojoResult LocalDataPipe::ConsumerBeginReadDataImplNoLock( |
266 const void** buffer, | 266 const void** buffer, |
267 uint32_t* buffer_num_bytes, | 267 uint32_t* buffer_num_bytes, |
268 bool all_or_none) { | 268 bool all_or_none) { |
269 size_t max_num_bytes_to_read = GetMaxNumBytesToReadNoLock(); | 269 size_t max_num_bytes_to_read = GetMaxNumBytesToReadNoLock(); |
270 if (all_or_none && *buffer_num_bytes > max_num_bytes_to_read) { | 270 if (all_or_none && *buffer_num_bytes > max_num_bytes_to_read) { |
271 // Don't return "should wait" since you can't wait for a specified amount of | 271 // Don't return "should wait" since you can't wait for a specified amount of |
272 // data. | 272 // data. |
273 return MOJO_RESULT_OUT_OF_RANGE; | 273 return producer_open_no_lock() ? MOJO_RESULT_OUT_OF_RANGE : |
| 274 MOJO_RESULT_FAILED_PRECONDITION; |
274 } | 275 } |
275 | 276 |
276 // Don't go into a two-phase read if there's no data. | 277 // Don't go into a two-phase read if there's no data. |
277 if (max_num_bytes_to_read == 0) { | 278 if (max_num_bytes_to_read == 0) { |
278 return producer_open_no_lock() ? MOJO_RESULT_SHOULD_WAIT : | 279 return producer_open_no_lock() ? MOJO_RESULT_SHOULD_WAIT : |
279 MOJO_RESULT_FAILED_PRECONDITION; | 280 MOJO_RESULT_FAILED_PRECONDITION; |
280 } | 281 } |
281 | 282 |
282 *buffer = buffer_.get() + start_index_; | 283 *buffer = buffer_.get() + start_index_; |
283 *buffer_num_bytes = static_cast<uint32_t>(max_num_bytes_to_read); | 284 *buffer_num_bytes = static_cast<uint32_t>(max_num_bytes_to_read); |
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
354 } | 355 } |
355 | 356 |
356 size_t LocalDataPipe::GetMaxNumBytesToReadNoLock() { | 357 size_t LocalDataPipe::GetMaxNumBytesToReadNoLock() { |
357 if (start_index_ + current_num_bytes_ > capacity_num_bytes()) | 358 if (start_index_ + current_num_bytes_ > capacity_num_bytes()) |
358 return capacity_num_bytes() - start_index_; | 359 return capacity_num_bytes() - start_index_; |
359 return current_num_bytes_; | 360 return current_num_bytes_; |
360 } | 361 } |
361 | 362 |
362 } // namespace system | 363 } // namespace system |
363 } // namespace mojo | 364 } // namespace mojo |
OLD | NEW |