Loading libs/binder/Parcel.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -521,6 +521,25 @@ int Parcel::compareData(const Parcel& other) { return memcmp(data(), other.data(), size); } status_t Parcel::compareDataInRange(size_t thisOffset, const Parcel& other, size_t otherOffset, size_t len, int* result) const { if (len > INT32_MAX || thisOffset > INT32_MAX || otherOffset > INT32_MAX) { // Don't accept size_t values which may have come from an inadvertent conversion from a // negative int. return BAD_VALUE; } size_t thisLimit; if (__builtin_add_overflow(thisOffset, len, &thisLimit) || thisLimit > mDataSize) { return BAD_VALUE; } size_t otherLimit; if (__builtin_add_overflow(otherOffset, len, &otherLimit) || otherLimit > other.mDataSize) { return BAD_VALUE; } *result = memcmp(data() + thisOffset, other.data() + otherOffset, len); return NO_ERROR; } bool Parcel::allowFds() const { return mAllowFds; Loading libs/binder/include/binder/Parcel.h +2 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,8 @@ public: size_t start, size_t len); int compareData(const Parcel& other); status_t compareDataInRange(size_t thisOffset, const Parcel& other, size_t otherOffset, size_t length, int* result) const; bool allowFds() const; bool pushAllowFds(bool allowFds); Loading libs/binder/tests/parcel_fuzzer/binder.cpp +9 −0 Original line number Diff line number Diff line Loading @@ -308,6 +308,15 @@ std::vector<ParcelRead<::android::Parcel>> BINDER_PARCEL_READ_FUNCTIONS { status_t status = p.hasFileDescriptorsInRange(offset, length, &result); FUZZ_LOG() << " status: " << status << " result: " << result; }, [] (const ::android::Parcel& p, uint8_t /* data */) { FUZZ_LOG() << "about to call compareDataInRange() with status"; size_t thisOffset = p.readUint32(); size_t otherOffset = p.readUint32(); size_t length = p.readUint32(); int result; status_t status = p.compareDataInRange(thisOffset, p, otherOffset, length, &result); FUZZ_LOG() << " status: " << status << " result: " << result; }, }; // clang-format on #pragma clang diagnostic pop Loading
libs/binder/Parcel.cpp +19 −0 Original line number Diff line number Diff line Loading @@ -521,6 +521,25 @@ int Parcel::compareData(const Parcel& other) { return memcmp(data(), other.data(), size); } status_t Parcel::compareDataInRange(size_t thisOffset, const Parcel& other, size_t otherOffset, size_t len, int* result) const { if (len > INT32_MAX || thisOffset > INT32_MAX || otherOffset > INT32_MAX) { // Don't accept size_t values which may have come from an inadvertent conversion from a // negative int. return BAD_VALUE; } size_t thisLimit; if (__builtin_add_overflow(thisOffset, len, &thisLimit) || thisLimit > mDataSize) { return BAD_VALUE; } size_t otherLimit; if (__builtin_add_overflow(otherOffset, len, &otherLimit) || otherLimit > other.mDataSize) { return BAD_VALUE; } *result = memcmp(data() + thisOffset, other.data() + otherOffset, len); return NO_ERROR; } bool Parcel::allowFds() const { return mAllowFds; Loading
libs/binder/include/binder/Parcel.h +2 −0 Original line number Diff line number Diff line Loading @@ -81,6 +81,8 @@ public: size_t start, size_t len); int compareData(const Parcel& other); status_t compareDataInRange(size_t thisOffset, const Parcel& other, size_t otherOffset, size_t length, int* result) const; bool allowFds() const; bool pushAllowFds(bool allowFds); Loading
libs/binder/tests/parcel_fuzzer/binder.cpp +9 −0 Original line number Diff line number Diff line Loading @@ -308,6 +308,15 @@ std::vector<ParcelRead<::android::Parcel>> BINDER_PARCEL_READ_FUNCTIONS { status_t status = p.hasFileDescriptorsInRange(offset, length, &result); FUZZ_LOG() << " status: " << status << " result: " << result; }, [] (const ::android::Parcel& p, uint8_t /* data */) { FUZZ_LOG() << "about to call compareDataInRange() with status"; size_t thisOffset = p.readUint32(); size_t otherOffset = p.readUint32(); size_t length = p.readUint32(); int result; status_t status = p.compareDataInRange(thisOffset, p, otherOffset, length, &result); FUZZ_LOG() << " status: " << status << " result: " << result; }, }; // clang-format on #pragma clang diagnostic pop