Skip to content

Commit 87534f0

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

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
@@ -1090,6 +1090,10 @@ void* Parcel::writeInplace(size_t len)
10901090
//printf("Writing %ld bytes, padded to %ld\n", len, padded);
10911091
uint8_t* const data = mData+mDataPos;
10921092

1093+
if (status_t status = validateReadData(mDataPos + padded); status != OK) {
1094+
return nullptr; // drops status
1095+
}
1096+
10931097
// Need to pad at end?
10941098
if (padded != len) {
10951099
#if BYTE_ORDER == BIG_ENDIAN
@@ -1648,6 +1652,10 @@ status_t Parcel::writeObject(const flat_binder_object& val, bool nullMetaData)
16481652
const bool enoughObjects = kernelFields->mObjectsSize < kernelFields->mObjectsCapacity;
16491653
if (enoughData && enoughObjects) {
16501654
restart_write:
1655+
if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) {
1656+
return status;
1657+
}
1658+
16511659
*reinterpret_cast<flat_binder_object*>(mData+mDataPos) = val;
16521660

16531661
// remember if it's a file descriptor
@@ -1889,6 +1897,10 @@ status_t Parcel::writeAligned(T val) {
18891897

18901898
if ((mDataPos+sizeof(val)) <= mDataCapacity) {
18911899
restart_write:
1900+
if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) {
1901+
return status;
1902+
}
1903+
18921904
memcpy(mData + mDataPos, &val, sizeof(val));
18931905
return finishWrite(sizeof(val));
18941906
}

0 commit comments

Comments
 (0)