diff options
| author | 2019-10-29 16:44:19 -0700 | |
|---|---|---|
| committer | 2020-02-18 10:16:52 -0800 | |
| commit | 0bb330d1218e18127eb3b996645da98d320bbf03 (patch) | |
| tree | 6f142a977bf38ea090bb5b57c0af57cd4143443e | |
| parent | 5f28d3c73290e350ea730e31b5209d27e4a760c6 (diff) | |
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
| -rw-r--r-- | libs/binder/Parcel.cpp | 16 | ||||
| -rw-r--r-- | libs/binder/include/binder/Parcel.h | 3 |
2 files changed, 16 insertions, 3 deletions
diff --git a/libs/binder/Parcel.cpp b/libs/binder/Parcel.cpp index 822247f561..f1077ae140 100644 --- a/libs/binder/Parcel.cpp +++ b/libs/binder/Parcel.cpp @@ -558,6 +558,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(); if (threadState == nullptr) { @@ -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; } } diff --git a/libs/binder/include/binder/Parcel.h b/libs/binder/include/binder/Parcel.h index d4bb85b102..4b1a758f38 100644 --- a/libs/binder/include/binder/Parcel.h +++ b/libs/binder/include/binder/Parcel.h @@ -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(); |