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

Commit 0bb330d1 authored by Daniel Colascione's avatar Daniel Colascione
Browse files

Remove heap allocations from Parcel::enforceInterface

We shouldn't have to make String16 instances just to do string
comparisons.

Bug: 143567784
Test: boots; 15 minutes of parcel fuzz testing
Change-Id: I9a152f1774103a551d5fd4a8412b42c52a2bb329
parent 5f28d3c7
Loading
Loading
Loading
Loading
+13 −3
Original line number Diff line number Diff line
@@ -557,6 +557,13 @@ bool Parcel::checkInterface(IBinder* binder) const

bool Parcel::enforceInterface(const String16& interface,
                              IPCThreadState* threadState) const
{
    return enforceInterface(interface.string(), interface.size(), threadState);
}

bool Parcel::enforceInterface(const char16_t* interface,
                              size_t len,
                              IPCThreadState* threadState) const
{
    // StrictModePolicy.
    int32_t strictPolicy = readInt32();
@@ -584,12 +591,15 @@ bool Parcel::enforceInterface(const String16& interface,
        return false;
    }
    // Interface descriptor.
    const String16 str(readString16());
    if (str == interface) {
    size_t parcel_interface_len;
    const char16_t* parcel_interface = readString16Inplace(&parcel_interface_len);
    if (len == parcel_interface_len &&
            (!len || !memcmp(parcel_interface, interface, len * sizeof (char16_t)))) {
        return true;
    } else {
        ALOGW("**** enforceInterface() expected '%s' but read '%s'",
                String8(interface).string(), String8(str).string());
              String8(interface, len).string(),
              String8(parcel_interface, parcel_interface_len).string());
        return false;
    }
}
+3 −0
Original line number Diff line number Diff line
@@ -96,6 +96,9 @@ public:
    // passed in.
    bool                enforceInterface(const String16& interface,
                                         IPCThreadState* threadState = nullptr) const;
    bool                enforceInterface(const char16_t* interface,
                                         size_t len,
                                         IPCThreadState* threadState = nullptr) const;
    bool                checkInterface(IBinder*) const;

    void                freeData();