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/system/local_data_pipe.h" | 11 #include "mojo/edk/system/local_data_pipe.h" |
12 | 12 |
13 #include <string.h> | 13 #include <string.h> |
14 | 14 |
15 #include <algorithm> | 15 #include <algorithm> |
16 | 16 |
17 #include "base/logging.h" | 17 #include "base/logging.h" |
18 #include "mojo/system/constants.h" | 18 #include "mojo/edk/system/constants.h" |
19 | 19 |
20 namespace mojo { | 20 namespace mojo { |
21 namespace system { | 21 namespace system { |
22 | 22 |
23 LocalDataPipe::LocalDataPipe(const MojoCreateDataPipeOptions& options) | 23 LocalDataPipe::LocalDataPipe(const MojoCreateDataPipeOptions& options) |
24 : DataPipe(true, true, options), start_index_(0), current_num_bytes_(0) { | 24 : DataPipe(true, true, options), start_index_(0), current_num_bytes_(0) { |
25 // Note: |buffer_| is lazily allocated, since a common case will be that one | 25 // Note: |buffer_| is lazily allocated, since a common case will be that one |
26 // of the handles is immediately passed off to another process. | 26 // of the handles is immediately passed off to another process. |
27 } | 27 } |
28 | 28 |
(...skipping 303 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
332 | 332 |
333 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) { | 333 void LocalDataPipe::MarkDataAsConsumedNoLock(size_t num_bytes) { |
334 DCHECK_LE(num_bytes, current_num_bytes_); | 334 DCHECK_LE(num_bytes, current_num_bytes_); |
335 start_index_ += num_bytes; | 335 start_index_ += num_bytes; |
336 start_index_ %= capacity_num_bytes(); | 336 start_index_ %= capacity_num_bytes(); |
337 current_num_bytes_ -= num_bytes; | 337 current_num_bytes_ -= num_bytes; |
338 } | 338 } |
339 | 339 |
340 } // namespace system | 340 } // namespace system |
341 } // namespace mojo | 341 } // namespace mojo |
OLD | NEW |