Merge "Fix addition/overflow checks." into qt-qpr1-dev am: af8f6cf3ab
Change-Id: I4f604cb104cc49b7e8f6612f1033a113faf51a48
This commit is contained in:
commit
c7589f2907
2 changed files with 10 additions and 3 deletions
|
@ -49,9 +49,10 @@ struct BufferedTextOutput::BufferState : public RefBase
|
|||
}
|
||||
|
||||
status_t append(const char* txt, size_t len) {
|
||||
if (len > SIZE_MAX - bufferPos) return NO_MEMORY; // overflow
|
||||
if ((len+bufferPos) > bufferSize) {
|
||||
if ((len + bufferPos) > SIZE_MAX / 3) return NO_MEMORY; // overflow
|
||||
size_t newSize = ((len+bufferPos)*3)/2;
|
||||
if (newSize < (len+bufferPos)) return NO_MEMORY; // overflow
|
||||
void* b = realloc(buffer, newSize);
|
||||
if (!b) return NO_MEMORY;
|
||||
buffer = (char*)b;
|
||||
|
|
|
@ -422,8 +422,10 @@ status_t Parcel::appendFrom(const Parcel *parcel, size_t offset, size_t len)
|
|||
const sp<ProcessState> proc(ProcessState::self());
|
||||
// grow objects
|
||||
if (mObjectsCapacity < mObjectsSize + numObjects) {
|
||||
if ((size_t) numObjects > SIZE_MAX - mObjectsSize) return NO_MEMORY; // overflow
|
||||
if (mObjectsSize + numObjects > SIZE_MAX / 3) return NO_MEMORY; // overflow
|
||||
size_t newSize = ((mObjectsSize + numObjects)*3)/2;
|
||||
if (newSize*sizeof(binder_size_t) < mObjectsSize) return NO_MEMORY; // overflow
|
||||
if (newSize > SIZE_MAX / sizeof(binder_size_t)) return NO_MEMORY; // overflow
|
||||
binder_size_t *objects =
|
||||
(binder_size_t*)realloc(mObjects, newSize*sizeof(binder_size_t));
|
||||
if (objects == (binder_size_t*)nullptr) {
|
||||
|
@ -1373,8 +1375,10 @@ restart_write:
|
|||
if (err != NO_ERROR) return err;
|
||||
}
|
||||
if (!enoughObjects) {
|
||||
if (mObjectsSize > SIZE_MAX - 2) return NO_MEMORY; // overflow
|
||||
if ((mObjectsSize + 2) > SIZE_MAX / 3) return NO_MEMORY; // overflow
|
||||
size_t newSize = ((mObjectsSize+2)*3)/2;
|
||||
if (newSize*sizeof(binder_size_t) < mObjectsSize) return NO_MEMORY; // overflow
|
||||
if (newSize > SIZE_MAX / sizeof(binder_size_t)) return NO_MEMORY; // overflow
|
||||
binder_size_t* objects = (binder_size_t*)realloc(mObjects, newSize*sizeof(binder_size_t));
|
||||
if (objects == nullptr) return NO_MEMORY;
|
||||
mObjects = objects;
|
||||
|
@ -2606,6 +2610,8 @@ status_t Parcel::growData(size_t len)
|
|||
return BAD_VALUE;
|
||||
}
|
||||
|
||||
if (len > SIZE_MAX - mDataSize) return NO_MEMORY; // overflow
|
||||
if (mDataSize + len > SIZE_MAX / 3) return NO_MEMORY; // overflow
|
||||
size_t newSize = ((mDataSize+len)*3)/2;
|
||||
return (newSize <= mDataSize)
|
||||
? (status_t) NO_MEMORY
|
||||
|
|
Loading…
Reference in a new issue