Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 3c9d6496 authored by Bernardo Rufino's avatar Bernardo Rufino Committed by Automerger Merge Worker
Browse files

Merge "Add native range-based Parcel::compareDataInRange()" am: 3810e23f

Original change: https://android-review.googlesource.com/c/platform/frameworks/native/+/1854415

Change-Id: I50e87e40aeacf4b24363e547f081bedddbfd99c2
parents 358fce25 3810e23f
Loading
Loading
Loading
Loading
+19 −0
Original line number Diff line number Diff line
@@ -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;
+2 −0
Original line number Diff line number Diff line
@@ -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);
+9 −0
Original line number Diff line number Diff line
@@ -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