Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(126)

Side by Side Diff: base/pickle.cc

Issue 9694034: Fix PickleIterator::GetReadPointerAndAdvance() not to produce wild addresses (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/pickle.h" 5 #include "base/pickle.h"
6 6
7 #include <stdlib.h> 7 #include <stdlib.h>
8 8
9 #include <algorithm> // for max() 9 #include <algorithm> // for max()
10 10
(...skipping 27 matching lines...) Expand all
38 if (read_ptr_ + sizeof(Type) > read_end_ptr_) 38 if (read_ptr_ + sizeof(Type) > read_end_ptr_)
39 return NULL; 39 return NULL;
40 if (sizeof(Type) < sizeof(uint32)) 40 if (sizeof(Type) < sizeof(uint32))
41 read_ptr_ += AlignInt(sizeof(Type), sizeof(uint32)); 41 read_ptr_ += AlignInt(sizeof(Type), sizeof(uint32));
42 else 42 else
43 read_ptr_ += sizeof(Type); 43 read_ptr_ += sizeof(Type);
44 return current_read_ptr; 44 return current_read_ptr;
45 } 45 }
46 46
47 const char* PickleIterator::GetReadPointerAndAdvance(int num_bytes) { 47 const char* PickleIterator::GetReadPointerAndAdvance(int num_bytes) {
48 if (num_bytes < 0 || read_end_ptr_ - read_ptr_ < num_bytes)
jbates 2012/03/13 16:52:44 Much cleaner!
49 return NULL;
48 const char* current_read_ptr = read_ptr_; 50 const char* current_read_ptr = read_ptr_;
49 const char* end_data_ptr = read_ptr_ + num_bytes;
50 if (num_bytes < 0)
51 return NULL;
52 // Check for enough space and for wrapping.
53 if (end_data_ptr > read_end_ptr_ || end_data_ptr < current_read_ptr)
54 return NULL;
55 read_ptr_ += AlignInt(num_bytes, sizeof(uint32)); 51 read_ptr_ += AlignInt(num_bytes, sizeof(uint32));
56 return current_read_ptr; 52 return current_read_ptr;
57 } 53 }
58 54
59 inline const char* PickleIterator::GetReadPointerAndAdvance(int num_elements, 55 inline const char* PickleIterator::GetReadPointerAndAdvance(int num_elements,
60 size_t size_element) { 56 size_t size_element) {
61 // Check for int32 overflow. 57 // Check for int32 overflow.
62 int64 num_bytes = static_cast<int64>(num_elements) * size_element; 58 int64 num_bytes = static_cast<int64>(num_elements) * size_element;
63 int num_bytes32 = static_cast<int>(num_bytes); 59 int num_bytes32 = static_cast<int>(num_bytes);
64 if (num_bytes != static_cast<int64>(num_bytes32)) 60 if (num_bytes != static_cast<int64>(num_bytes32))
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
356 return NULL; 352 return NULL;
357 353
358 const Header* hdr = reinterpret_cast<const Header*>(start); 354 const Header* hdr = reinterpret_cast<const Header*>(start);
359 const char* payload_base = start + header_size; 355 const char* payload_base = start + header_size;
360 const char* payload_end = payload_base + hdr->payload_size; 356 const char* payload_end = payload_base + hdr->payload_size;
361 if (payload_end < payload_base) 357 if (payload_end < payload_base)
362 return NULL; 358 return NULL;
363 359
364 return (payload_end > end) ? NULL : payload_end; 360 return (payload_end > end) ? NULL : payload_end;
365 } 361 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698