Skip to content

Commit 03fd6d4

Browse files
Steven Morelandandroid-build-merge-worker-robot
authored andcommitted
Merge "libbinder: Parcel: validate read data before write" into sc-dev am: 538e27f am: f0d7060
Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/native/+/30026350 Change-Id: I256a524288cb7f615fd85fd2bb74435ce8a61180 Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
2 parents 1450611 + f0d7060 commit 03fd6d4

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

799+
if (status_t status = validateReadData(mDataPos + padded); status != OK) {
800+
return nullptr; // drops status
801+
}
802+
799803
// Need to pad at end?
800804
if (padded != len) {
801805
#if BYTE_ORDER == BIG_ENDIAN
@@ -1313,6 +1317,10 @@ status_t Parcel::writeObject(const flat_binder_object& val, bool nullMetaData)
13131317
const bool enoughObjects = mObjectsSize < mObjectsCapacity;
13141318
if (enoughData && enoughObjects) {
13151319
restart_write:
1320+
if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) {
1321+
return status;
1322+
}
1323+
13161324
*reinterpret_cast<flat_binder_object*>(mData+mDataPos) = val;
13171325

13181326
// remember if it's a file descriptor
@@ -1505,6 +1513,10 @@ status_t Parcel::writeAligned(T val) {
15051513

15061514
if ((mDataPos+sizeof(val)) <= mDataCapacity) {
15071515
restart_write:
1516+
if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) {
1517+
return status;
1518+
}
1519+
15081520
*reinterpret_cast<T*>(mData+mDataPos) = val;
15091521
return finishWrite(sizeof(val));
15101522
}

0 commit comments

Comments
 (0)