From 7a450244904674f78dfe7d9cb6bd96f04727131c Mon Sep 17 00:00:00 2001 From: Devin Moore Date: Tue, 15 Nov 2022 22:21:07 +0000 Subject: libbinder_ndk: more accurate error for array allocator failure The allocator can fail due to no memory. In the non-nullable case, it can also fail if the array is null. So we return STATUS_UNEXPECTED_NULL in those cases. Test: run the following with local changes to remove the oemlock HIDL service and applying patchset 2 of ag/20460045 Test: atest GtsOemLockServiceTestCases Bug: na Change-Id: I385780cd407e2d0b5707032ff39ae20c937eea66 --- libs/binder/ndk/parcel.cpp | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) (limited to 'libs') diff --git a/libs/binder/ndk/parcel.cpp b/libs/binder/ndk/parcel.cpp index c320e8d6df..86930229ce 100644 --- a/libs/binder/ndk/parcel.cpp +++ b/libs/binder/ndk/parcel.cpp @@ -129,7 +129,13 @@ binder_status_t ReadArray(const AParcel* parcel, void* arrayData, } T* array; - if (!allocator(arrayData, length, &array)) return STATUS_NO_MEMORY; + if (!allocator(arrayData, length, &array)) { + if (length < 0) { + return STATUS_UNEXPECTED_NULL; + } else { + return STATUS_NO_MEMORY; + } + } if (length <= 0) return STATUS_OK; if (array == nullptr) return STATUS_NO_MEMORY; @@ -157,7 +163,13 @@ binder_status_t ReadArray(const AParcel* parcel, void* arrayData, } char16_t* array; - if (!allocator(arrayData, length, &array)) return STATUS_NO_MEMORY; + if (!allocator(arrayData, length, &array)) { + if (length < 0) { + return STATUS_UNEXPECTED_NULL; + } else { + return STATUS_NO_MEMORY; + } + } if (length <= 0) return STATUS_OK; if (array == nullptr) return STATUS_NO_MEMORY; @@ -204,7 +216,13 @@ binder_status_t ReadArray(const AParcel* parcel, void* arrayData, ArrayAllocator return status; } - if (!allocator(arrayData, length)) return STATUS_NO_MEMORY; + if (!allocator(arrayData, length)) { + if (length < 0) { + return STATUS_UNEXPECTED_NULL; + } else { + return STATUS_NO_MEMORY; + } + } if (length <= 0) return STATUS_OK; -- cgit v1.2.3-59-g8ed1b