diff options
author | Christopher Tate <ctate@google.com> | 2015-06-08 14:45:14 -0700 |
---|---|---|
committer | Christopher Tate <ctate@google.com> | 2015-06-08 14:49:09 -0700 |
commit | ed7a50cc7d490ae7aece2d16422c5f7941876468 (patch) | |
tree | a8c6d660d656e0d5a79cb2ed20f859b8a86e1426 /libs/binder/Parcel.cpp | |
parent | 98e67d352b8805a868ca0e7c2be3ea830fb7c338 (diff) | |
download | frameworks_native-ed7a50cc7d490ae7aece2d16422c5f7941876468.zip frameworks_native-ed7a50cc7d490ae7aece2d16422c5f7941876468.tar.gz frameworks_native-ed7a50cc7d490ae7aece2d16422c5f7941876468.tar.bz2 |
Prevent integer overflow when calculating buffer resizes
Make sure that we don't go haywire if an exponential buffer growth
operation winds up wrapping integer range. Along the way, fix a
bookkeeping bug in BufferedTextOutput that would cause it to keep
spuriously realloc()ing on every append().
Bug 20674694
Change-Id: Ia845b7de36b90672a151a918ffc26c7da68e20a2
Diffstat (limited to 'libs/binder/Parcel.cpp')
-rw-r--r-- | libs/binder/Parcel.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 2ebf617..31667d9 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -484,7 +484,8 @@ status_t Parcel::appendFrom(const Parcel *parcel, size_t offset, size_t len) if (numObjects > 0) { // grow objects if (mObjectsCapacity < mObjectsSize + numObjects) { - int newSize = ((mObjectsSize + numObjects)*3)/2; + size_t newSize = ((mObjectsSize + numObjects)*3)/2; + if (newSize < mObjectsSize) return NO_MEMORY; // overflow binder_size_t *objects = (binder_size_t*)realloc(mObjects, newSize*sizeof(binder_size_t)); if (objects == (binder_size_t*)0) { @@ -1038,6 +1039,7 @@ restart_write: } if (!enoughObjects) { size_t newSize = ((mObjectsSize+2)*3)/2; + if (newSize < mObjectsSize) return NO_MEMORY; // overflow binder_size_t* objects = (binder_size_t*)realloc(mObjects, newSize*sizeof(binder_size_t)); if (objects == NULL) return NO_MEMORY; mObjects = objects; |