Skip to content

Commit fb27f09

Browse files
Steven Morelandandroid-build-merge-worker-robot
authored andcommitted
Merge "libbinder: Parcel: validate read data before write" into tm-dev am: fde1dbb
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/30026349 Change-Id: I50a1109ea468e66ccc657014a22f83914b2f16e5 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2 parents 7fe9e79 + fde1dbb commit fb27f09

1 file changed

Lines changed: 12 additions & 0 deletions

File tree

libs/binder/Parcel.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -888,6 +888,10 @@ void* Parcel::writeInplace(size_t len)
888888
//printf("Writing %ld bytes, padded to %ld\n", len, padded);
889889
uint8_t* const data = mData+mDataPos;
890890

891+
if (status_t status = validateReadData(mDataPos + padded); status != OK) {
892+
return nullptr; // drops status
893+
}
894+
891895
// Need to pad at end?
892896
if (padded != len) {
893897
#if BYTE_ORDER == BIG_ENDIAN
@@ -1405,6 +1409,10 @@ status_t Parcel::writeObject(const flat_binder_object& val, bool nullMetaData)
14051409
const bool enoughObjects = mObjectsSize < mObjectsCapacity;
14061410
if (enoughData && enoughObjects) {
14071411
restart_write:
1412+
if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) {
1413+
return status;
1414+
}
1415+
14081416
*reinterpret_cast<flat_binder_object*>(mData+mDataPos) = val;
14091417

14101418
// remember if it's a file descriptor
@@ -1621,6 +1629,10 @@ status_t Parcel::writeAligned(T val) {
16211629

16221630
if ((mDataPos+sizeof(val)) <= mDataCapacity) {
16231631
restart_write:
1632+
if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) {
1633+
return status;
1634+
}
1635+
16241636
memcpy(mData + mDataPos, &val, sizeof(val));
16251637
return finishWrite(sizeof(val));
16261638
}

0 commit comments

Comments
 (0)