From 8b64307e958771edc465910e3c053cdc351dcafe Mon Sep 17 00:00:00 2001 From: Christopher Tate Date: Thu, 3 Nov 2016 13:32:41 -0700 Subject: [PATCH] Correct overflow check in Parcel resize code Bug 31929765 Change-Id: Ie27b9945f1de056624668869bdf9a5578abff467 --- libs/binder/Parcel.cpp | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 172db27ab8..1e7df6c435 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -417,7 +417,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*sizeof(binder_size_t) < 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) { @@ -943,6 +944,7 @@ restart_write: } if (!enoughObjects) { size_t newSize = ((mObjectsSize+2)*3)/2; + if (newSize*sizeof(binder_size_t) < 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; -- 2.11.0