Skip to content

Commit d7fbe20

Browse files
Steven MorelandAndroid (Google) Code Review
authored andcommitted
Merge "libbinder: Parcel: validate read data before write" into main
2 parents cb31cab + c54dad6 commit d7fbe20

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

1189+
if (status_t status = validateReadData(mDataPos + padded); status != OK) {
1190+
return nullptr; // drops status
1191+
}
1192+
11891193
// Need to pad at end?
11901194
if (padded != len) {
11911195
#if BYTE_ORDER == BIG_ENDIAN
@@ -1774,6 +1778,10 @@ status_t Parcel::writeObject(const flat_binder_object& val, bool nullMetaData)
17741778
const bool enoughObjects = kernelFields->mObjectsSize < kernelFields->mObjectsCapacity;
17751779
if (enoughData && enoughObjects) {
17761780
restart_write:
1781+
if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) {
1782+
return status;
1783+
}
1784+
17771785
*reinterpret_cast<flat_binder_object*>(mData+mDataPos) = val;
17781786

17791787
// remember if it's a file descriptor
@@ -2020,6 +2028,10 @@ status_t Parcel::writeAligned(T val) {
20202028

20212029
if ((mDataPos+sizeof(val)) <= mDataCapacity) {
20222030
restart_write:
2031+
if (status_t status = validateReadData(mDataPos + sizeof(val)); status != OK) {
2032+
return status;
2033+
}
2034+
20232035
memcpy(mData + mDataPos, &val, sizeof(val));
20242036
return finishWrite(sizeof(val));
20252037
}

0 commit comments

Comments
 (0)