diff options
Diffstat (limited to 'libs')
| -rw-r--r-- | libs/binder/ndk/include_cpp/android/binder_parcel_utils.h | 46 | ||||
| -rw-r--r-- | libs/binder/tests/parcel_fuzzer/binder_ndk.cpp | 3 |
2 files changed, 32 insertions, 17 deletions
diff --git a/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h b/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h index 4a7b66474a..2b18a0a1e0 100644 --- a/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h +++ b/libs/binder/ndk/include_cpp/android/binder_parcel_utils.h @@ -550,8 +550,8 @@ binder_status_t AParcel_writeNullableStdVectorParcelableElement(AParcel* parcel, const void* vectorData, size_t index) { const std::optional<std::vector<P>>* vector = - static_cast<const std::optional<std::vector<P>*>>(vectorData); - return AParcel_writeNullableParcelable(parcel, vector->at(index)); + static_cast<const std::optional<std::vector<P>>*>(vectorData); + return AParcel_writeNullableParcelable(parcel, (*vector)->at(index)); } /** @@ -561,7 +561,7 @@ template <typename P> binder_status_t AParcel_readNullableStdVectorParcelableElement(const AParcel* parcel, void* vectorData, size_t index) { std::optional<std::vector<P>>* vector = static_cast<std::optional<std::vector<P>>*>(vectorData); - return AParcel_readNullableParcelable(parcel, &vector->at(index)); + return AParcel_readNullableParcelable(parcel, &(*vector)->at(index)); } /** @@ -573,11 +573,7 @@ inline binder_status_t AParcel_writeStdVectorParcelableElement<ScopedFileDescrip AParcel* parcel, const void* vectorData, size_t index) { const std::vector<ScopedFileDescriptor>* vector = static_cast<const std::vector<ScopedFileDescriptor>*>(vectorData); - int writeFd = vector->at(index).get(); - if (writeFd < 0) { - return STATUS_UNEXPECTED_NULL; - } - return AParcel_writeParcelFileDescriptor(parcel, writeFd); + return AParcel_writeRequiredParcelFileDescriptor(parcel, vector->at(index)); } /** @@ -589,15 +585,31 @@ inline binder_status_t AParcel_readStdVectorParcelableElement<ScopedFileDescript const AParcel* parcel, void* vectorData, size_t index) { std::vector<ScopedFileDescriptor>* vector = static_cast<std::vector<ScopedFileDescriptor>*>(vectorData); - int readFd; - binder_status_t status = AParcel_readParcelFileDescriptor(parcel, &readFd); - if (status == STATUS_OK) { - if (readFd < 0) { - return STATUS_UNEXPECTED_NULL; - } - vector->at(index).set(readFd); - } - return status; + return AParcel_readRequiredParcelFileDescriptor(parcel, &vector->at(index)); +} + +/** + * Writes a ScopedFileDescriptor object inside a std::optional<std::vector<ScopedFileDescriptor>> at + * index 'index' to 'parcel'. + */ +template <> +inline binder_status_t AParcel_writeNullableStdVectorParcelableElement<ScopedFileDescriptor>( + AParcel* parcel, const void* vectorData, size_t index) { + const std::optional<std::vector<ScopedFileDescriptor>>* vector = + static_cast<const std::optional<std::vector<ScopedFileDescriptor>>*>(vectorData); + return AParcel_writeNullableParcelFileDescriptor(parcel, (*vector)->at(index)); +} + +/** + * Reads a ScopedFileDescriptor object inside a std::optional<std::vector<ScopedFileDescriptor>> at + * index 'index' from 'parcel'. + */ +template <> +inline binder_status_t AParcel_readNullableStdVectorParcelableElement<ScopedFileDescriptor>( + const AParcel* parcel, void* vectorData, size_t index) { + std::optional<std::vector<ScopedFileDescriptor>>* vector = + static_cast<std::optional<std::vector<ScopedFileDescriptor>>*>(vectorData); + return AParcel_readNullableParcelFileDescriptor(parcel, &(*vector)->at(index)); } /** diff --git a/libs/binder/tests/parcel_fuzzer/binder_ndk.cpp b/libs/binder/tests/parcel_fuzzer/binder_ndk.cpp index 0974d8e952..c0a762d1de 100644 --- a/libs/binder/tests/parcel_fuzzer/binder_ndk.cpp +++ b/libs/binder/tests/parcel_fuzzer/binder_ndk.cpp @@ -95,8 +95,11 @@ std::vector<ParcelRead<NdkParcelAdapter>> BINDER_NDK_PARCEL_READ_FUNCTIONS{ PARCEL_READ(std::vector<std::string>, ndk::AParcel_readVector), PARCEL_READ(std::optional<std::vector<std::optional<std::string>>>, ndk::AParcel_readVector), PARCEL_READ(std::vector<SomeParcelable>, ndk::AParcel_readVector), + PARCEL_READ(std::optional<std::vector<std::optional<SomeParcelable>>>, ndk::AParcel_readVector), PARCEL_READ(std::vector<ndk::SpAIBinder>, ndk::AParcel_readVector), PARCEL_READ(std::optional<std::vector<ndk::SpAIBinder>>, ndk::AParcel_readVector), + PARCEL_READ(std::vector<ndk::ScopedFileDescriptor>, ndk::AParcel_readVector), + PARCEL_READ(std::optional<std::vector<ndk::ScopedFileDescriptor>>, ndk::AParcel_readVector), PARCEL_READ(std::vector<int32_t>, ndk::AParcel_readVector), PARCEL_READ(std::optional<std::vector<int32_t>>, ndk::AParcel_readVector), PARCEL_READ(std::vector<uint32_t>, ndk::AParcel_readVector), |