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

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, 2 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 232266)
+++ base/pickle.cc (working copy)
@@ -35,7 +35,7 @@
template<typename Type>
inline const char* PickleIterator::GetReadPointerAndAdvance() {
const char* current_read_ptr = read_ptr_;
- if (read_ptr_ + sizeof(Type) > read_end_ptr_)
+ if (sizeof(Type) > static_cast<size_t>(read_end_ptr_ - read_ptr_))
return NULL;
if (sizeof(Type) < sizeof(uint32))
read_ptr_ += AlignInt(sizeof(Type), sizeof(uint32));
@@ -291,11 +291,10 @@
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;
}
template <size_t length> void Pickle::WriteBytesStatic(const void* data) {
« no previous file with comments | « AUTHORS ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698