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

Unified Diff: base/pickle.cc

Issue 12079010: Avoid undefined behavior when checking for pointer wraparound (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Created 7 years, 10 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: base/pickle.cc
===================================================================
--- base/pickle.cc (revision 178847)
+++ base/pickle.cc (working copy)
@@ -35,12 +35,14 @@
template<typename Type>
inline const char* PickleIterator::GetReadPointerAndAdvance() {
const char* current_read_ptr = read_ptr_;
- if (read_ptr_ + sizeof(Type) > read_end_ptr_)
- return NULL;
+ size_t s;
jar (doing other things) 2013/03/04 19:25:51 nit: style guide suggests avoiding single characte
if (sizeof(Type) < sizeof(uint32))
- read_ptr_ += AlignInt(sizeof(Type), sizeof(uint32));
+ s = AlignInt(sizeof(Type), sizeof(uint32));
jar (doing other things) 2013/03/04 19:25:51 Am I correct in reading AlignInt(smaller, larger)
else
- read_ptr_ += sizeof(Type);
+ s = sizeof(Type);
+ if (s > static_cast<size_t>(read_end_ptr_ - read_ptr_))
+ return NULL;
+ read_ptr_ += s;
return current_read_ptr;
}
@@ -353,9 +355,8 @@
const Header* hdr = reinterpret_cast<const Header*>(start);
const char* payload_base = start + header_size;
- const char* payload_end = payload_base + hdr->payload_size;
- if (payload_end < payload_base)
+ if (hdr->payload_size > static_cast<size_t>(end - payload_base))
return NULL;
- return (payload_end > end) ? NULL : payload_end;
+ return payload_base + hdr->payload_size;
}
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698