| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2019 The Android Open Source Project | 
 | 3 |  * | 
 | 4 |  * Licensed under the Apache License, Version 2.0 (the "License"); | 
 | 5 |  * you may not use this file except in compliance with the License. | 
 | 6 |  * You may obtain a copy of the License at | 
 | 7 |  * | 
 | 8 |  *      http://www.apache.org/licenses/LICENSE-2.0 | 
 | 9 |  * | 
 | 10 |  * Unless required by applicable law or agreed to in writing, software | 
 | 11 |  * distributed under the License is distributed on an "AS IS" BASIS, | 
 | 12 |  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | 
 | 13 |  * See the License for the specific language governing permissions and | 
 | 14 |  * limitations under the License. | 
 | 15 |  */ | 
 | 16 | #define FUZZ_LOG_TAG "binder" | 
 | 17 |  | 
 | 18 | #include "binder.h" | 
 | 19 | #include "util.h" | 
 | 20 |  | 
| Steven Moreland | 7c7c648 | 2019-09-30 12:32:02 -0700 | [diff] [blame] | 21 | #include <android/os/IServiceManager.h> | 
| Steven Moreland | d115f83 | 2020-09-22 21:01:35 +0000 | [diff] [blame] | 22 | #include <binder/ParcelableHolder.h> | 
 | 23 | #include <binder/PersistableBundle.h> | 
| Steven Moreland | 7c7c648 | 2019-09-30 12:32:02 -0700 | [diff] [blame] | 24 |  | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 25 | using ::android::status_t; | 
 | 26 |  | 
| Steven Moreland | 9cb1e6a | 2019-10-15 17:20:51 -0700 | [diff] [blame] | 27 | enum ByteEnum : int8_t {}; | 
 | 28 | enum IntEnum : int32_t {}; | 
 | 29 | enum LongEnum : int64_t {}; | 
 | 30 |  | 
| Steven Moreland | 7c7c648 | 2019-09-30 12:32:02 -0700 | [diff] [blame] | 31 | class ExampleParcelable : public android::Parcelable { | 
 | 32 | public: | 
 | 33 |     status_t writeToParcel(android::Parcel* /*parcel*/) const override { | 
 | 34 |         FUZZ_LOG() << "should not reach"; | 
 | 35 |         abort(); | 
 | 36 |     } | 
 | 37 |     status_t readFromParcel(const android::Parcel* parcel) override { | 
 | 38 |         mExampleExtraField++; | 
 | 39 |         return parcel->readInt64(&(this->mExampleUsedData)); | 
 | 40 |     } | 
 | 41 | private: | 
 | 42 |     int64_t mExampleExtraField = 0; | 
 | 43 |     int64_t mExampleUsedData = 0; | 
 | 44 | }; | 
 | 45 |  | 
| Steven Moreland | 6d81393 | 2019-09-30 15:31:35 -0700 | [diff] [blame] | 46 | struct ExampleFlattenable : public android::Flattenable<ExampleFlattenable> { | 
 | 47 | public: | 
 | 48 |     size_t getFlattenedSize() const { return sizeof(mValue); } | 
 | 49 |     size_t getFdCount() const { return 0; } | 
 | 50 |     status_t flatten(void*& /*buffer*/, size_t& /*size*/, int*& /*fds*/, size_t& /*count*/) const { | 
 | 51 |         FUZZ_LOG() << "should not reach"; | 
 | 52 |         abort(); | 
 | 53 |     } | 
 | 54 |     status_t unflatten(void const*& buffer, size_t& size, int const*& /*fds*/, size_t& /*count*/) { | 
 | 55 |         if (size < sizeof(mValue)) { | 
 | 56 |             return android::NO_MEMORY; | 
 | 57 |         } | 
 | 58 |         android::FlattenableUtils::read(buffer, size, mValue); | 
 | 59 |         return android::OK; | 
 | 60 |     } | 
 | 61 | private: | 
 | 62 |     int32_t mValue = 0xFEEDBEEF; | 
 | 63 | }; | 
 | 64 |  | 
 | 65 | struct ExampleLightFlattenable : public android::LightFlattenablePod<ExampleLightFlattenable> { | 
 | 66 |     int32_t mValue = 0; | 
 | 67 | }; | 
 | 68 |  | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 69 | #define PARCEL_READ_WITH_STATUS(T, FUN) \ | 
 | 70 |     [] (const ::android::Parcel& p, uint8_t /*data*/) {\ | 
 | 71 |         FUZZ_LOG() << "about to read " #T " using " #FUN " with status";\ | 
 | 72 |         T t{};\ | 
 | 73 |         status_t status = p.FUN(&t);\ | 
 | 74 |         FUZZ_LOG() << #T " status: " << status /* << " value: " << t*/;\ | 
 | 75 |     } | 
 | 76 |  | 
 | 77 | #define PARCEL_READ_NO_STATUS(T, FUN) \ | 
 | 78 |     [] (const ::android::Parcel& p, uint8_t /*data*/) {\ | 
 | 79 |         FUZZ_LOG() << "about to read " #T " using " #FUN " with no status";\ | 
 | 80 |         T t = p.FUN();\ | 
 | 81 |         (void) t;\ | 
 | 82 |         FUZZ_LOG() << #T " done " /* << " value: " << t*/;\ | 
 | 83 |     } | 
 | 84 |  | 
 | 85 | #define PARCEL_READ_OPT_STATUS(T, FUN) \ | 
 | 86 |     PARCEL_READ_WITH_STATUS(T, FUN), \ | 
 | 87 |     PARCEL_READ_NO_STATUS(T, FUN) | 
 | 88 |  | 
| Jooyung Han | ceae53e | 2020-11-18 12:17:50 +0900 | [diff] [blame] | 89 | #pragma clang diagnostic push | 
 | 90 | #pragma clang diagnostic ignored "-Wdeprecated-declarations" | 
| Steven Moreland | 9cb1e6a | 2019-10-15 17:20:51 -0700 | [diff] [blame] | 91 | // clang-format off | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 92 | std::vector<ParcelRead<::android::Parcel>> BINDER_PARCEL_READ_FUNCTIONS { | 
 | 93 |     PARCEL_READ_NO_STATUS(size_t, dataSize), | 
 | 94 |     PARCEL_READ_NO_STATUS(size_t, dataAvail), | 
 | 95 |     PARCEL_READ_NO_STATUS(size_t, dataPosition), | 
 | 96 |     PARCEL_READ_NO_STATUS(size_t, dataCapacity), | 
 | 97 |     [] (const ::android::Parcel& p, uint8_t pos) { | 
 | 98 |         FUZZ_LOG() << "about to setDataPosition: " << pos; | 
 | 99 |         p.setDataPosition(pos); | 
 | 100 |         FUZZ_LOG() << "setDataPosition done"; | 
 | 101 |     }, | 
 | 102 |     PARCEL_READ_NO_STATUS(size_t, allowFds), | 
 | 103 |     PARCEL_READ_NO_STATUS(size_t, hasFileDescriptors), | 
 | 104 |     [] (const ::android::Parcel& p, uint8_t len) { | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 105 |         std::string interface(len, 'a'); | 
 | 106 |         FUZZ_LOG() << "about to enforceInterface: " << interface; | 
 | 107 |         bool b = p.enforceInterface(::android::String16(interface.c_str())); | 
 | 108 |         FUZZ_LOG() << "enforced interface: " << b; | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 109 |     }, | 
 | 110 |     [] (const ::android::Parcel& p, uint8_t /*len*/) { | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 111 |         FUZZ_LOG() << "about to checkInterface"; | 
| Steven Moreland | 24bc0d1 | 2019-10-11 12:29:20 -0700 | [diff] [blame] | 112 |         android::sp<android::IBinder> aBinder = new android::BBinder(); | 
 | 113 |         bool b = p.checkInterface(aBinder.get()); | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 114 |         FUZZ_LOG() << "checked interface: " << b; | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 115 |     }, | 
 | 116 |     PARCEL_READ_NO_STATUS(size_t, objectsCount), | 
 | 117 |     PARCEL_READ_NO_STATUS(status_t, errorCheck), | 
 | 118 |     [] (const ::android::Parcel& p, uint8_t len) { | 
 | 119 |         FUZZ_LOG() << "about to read void*"; | 
 | 120 |         std::vector<uint8_t> data(len); | 
 | 121 |         status_t status = p.read(data.data(), len); | 
 | 122 |         FUZZ_LOG() << "read status: " << status; | 
 | 123 |     }, | 
 | 124 |     [] (const ::android::Parcel& p, uint8_t len) { | 
 | 125 |         FUZZ_LOG() << "about to readInplace"; | 
 | 126 |         const void* r = p.readInplace(len); | 
| Steven Moreland | 6065c05 | 2019-09-30 18:22:44 -0700 | [diff] [blame] | 127 |         FUZZ_LOG() << "readInplace done. pointer: " << r << " bytes: " << hexString(r, len); | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 128 |     }, | 
 | 129 |     PARCEL_READ_OPT_STATUS(int32_t, readInt32), | 
 | 130 |     PARCEL_READ_OPT_STATUS(uint32_t, readUint32), | 
 | 131 |     PARCEL_READ_OPT_STATUS(int64_t, readInt64), | 
 | 132 |     PARCEL_READ_OPT_STATUS(uint64_t, readUint64), | 
 | 133 |     PARCEL_READ_OPT_STATUS(float, readFloat), | 
 | 134 |     PARCEL_READ_OPT_STATUS(double, readDouble), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 135 |     PARCEL_READ_OPT_STATUS(bool, readBool), | 
 | 136 |     PARCEL_READ_OPT_STATUS(char16_t, readChar), | 
 | 137 |     PARCEL_READ_OPT_STATUS(int8_t, readByte), | 
 | 138 |  | 
 | 139 |     PARCEL_READ_WITH_STATUS(std::string, readUtf8FromUtf16), | 
 | 140 |     PARCEL_READ_WITH_STATUS(std::unique_ptr<std::string>, readUtf8FromUtf16), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 141 |     PARCEL_READ_WITH_STATUS(std::optional<std::string>, readUtf8FromUtf16), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 142 |     [] (const ::android::Parcel& p, uint8_t /*data*/) { | 
 | 143 |         FUZZ_LOG() << "about to read c-str"; | 
 | 144 |         const char* str = p.readCString(); | 
 | 145 |         FUZZ_LOG() << "read c-str: " << (str ? str : "<empty string>"); | 
 | 146 |     }, | 
 | 147 |     PARCEL_READ_OPT_STATUS(android::String8, readString8), | 
 | 148 |     PARCEL_READ_OPT_STATUS(android::String16, readString16), | 
 | 149 |     PARCEL_READ_WITH_STATUS(std::unique_ptr<android::String16>, readString16), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 150 |     PARCEL_READ_WITH_STATUS(std::optional<android::String16>, readString16), | 
| Steven Moreland | 7c7c648 | 2019-09-30 12:32:02 -0700 | [diff] [blame] | 151 |     [] (const ::android::Parcel& p, uint8_t /*data*/) { | 
 | 152 |         FUZZ_LOG() << "about to readString16Inplace"; | 
 | 153 |         size_t outLen = 0; | 
 | 154 |         const char16_t* str = p.readString16Inplace(&outLen); | 
| Steven Moreland | 6065c05 | 2019-09-30 18:22:44 -0700 | [diff] [blame] | 155 |         FUZZ_LOG() << "readString16Inplace: " << hexString(str, sizeof(char16_t) * outLen) | 
 | 156 |                    << " size: " << outLen; | 
| Steven Moreland | 7c7c648 | 2019-09-30 12:32:02 -0700 | [diff] [blame] | 157 |     }, | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 158 |     PARCEL_READ_WITH_STATUS(android::sp<android::IBinder>, readStrongBinder), | 
 | 159 |     PARCEL_READ_WITH_STATUS(android::sp<android::IBinder>, readNullableStrongBinder), | 
 | 160 |  | 
| Steven Moreland | 9cb1e6a | 2019-10-15 17:20:51 -0700 | [diff] [blame] | 161 |     // TODO(b/131868573): can force read of arbitrarily sized vector | 
 | 162 |     // PARCEL_READ_WITH_STATUS(std::vector<ByteEnum>, readEnumVector), | 
 | 163 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<ByteEnum>>, readEnumVector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 164 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<ByteEnum>>, readEnumVector), | 
| Steven Moreland | 9cb1e6a | 2019-10-15 17:20:51 -0700 | [diff] [blame] | 165 |     // PARCEL_READ_WITH_STATUS(std::vector<IntEnum>, readEnumVector), | 
 | 166 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<IntEnum>>, readEnumVector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 167 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<IntEnum>>, readEnumVector), | 
| Steven Moreland | 9cb1e6a | 2019-10-15 17:20:51 -0700 | [diff] [blame] | 168 |     // PARCEL_READ_WITH_STATUS(std::vector<LongEnum>, readEnumVector), | 
 | 169 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<LongEnum>>, readEnumVector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 170 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<LongEnum>>, readEnumVector), | 
| Steven Moreland | 9cb1e6a | 2019-10-15 17:20:51 -0700 | [diff] [blame] | 171 |  | 
| Steven Moreland | 7c7c648 | 2019-09-30 12:32:02 -0700 | [diff] [blame] | 172 |     // only reading one parcelable type for now | 
 | 173 |     // TODO(b/131868573): can force read of arbitrarily sized vector | 
 | 174 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<std::unique_ptr<ExampleParcelable>>>, readParcelableVector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 175 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<std::optional<ExampleParcelable>>>, readParcelableVector), | 
| Steven Moreland | 7c7c648 | 2019-09-30 12:32:02 -0700 | [diff] [blame] | 176 |     // PARCEL_READ_WITH_STATUS(std::vector<ExampleParcelable>, readParcelableVector), | 
 | 177 |     PARCEL_READ_WITH_STATUS(ExampleParcelable, readParcelable), | 
 | 178 |     PARCEL_READ_WITH_STATUS(std::unique_ptr<ExampleParcelable>, readParcelable), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 179 |     PARCEL_READ_WITH_STATUS(std::optional<ExampleParcelable>, readParcelable), | 
| Steven Moreland | 7c7c648 | 2019-09-30 12:32:02 -0700 | [diff] [blame] | 180 |  | 
 | 181 |     // only reading one binder type for now | 
 | 182 |     PARCEL_READ_WITH_STATUS(android::sp<android::os::IServiceManager>, readStrongBinder), | 
 | 183 |     PARCEL_READ_WITH_STATUS(android::sp<android::os::IServiceManager>, readNullableStrongBinder), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 184 |  | 
 | 185 |     // TODO(b/131868573): can force read of arbitrarily sized vector | 
 | 186 |     // PARCEL_READ_WITH_STATUS(::std::unique_ptr<std::vector<android::sp<android::IBinder>>>, readStrongBinderVector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 187 |     // PARCEL_READ_WITH_STATUS(::std::optional<std::vector<android::sp<android::IBinder>>>, readStrongBinderVector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 188 |     // PARCEL_READ_WITH_STATUS(std::vector<android::sp<android::IBinder>>, readStrongBinderVector), | 
 | 189 |  | 
 | 190 |     // TODO(b/131868573): can force read of arbitrarily sized vector | 
 | 191 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<int8_t>>, readByteVector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 192 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<int8_t>>, readByteVector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 193 |     // PARCEL_READ_WITH_STATUS(std::vector<int8_t>, readByteVector), | 
 | 194 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<uint8_t>>, readByteVector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 195 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<uint8_t>>, readByteVector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 196 |     // PARCEL_READ_WITH_STATUS(std::vector<uint8_t>, readByteVector), | 
 | 197 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<int32_t>>, readInt32Vector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 198 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<int32_t>>, readInt32Vector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 199 |     // PARCEL_READ_WITH_STATUS(std::vector<int32_t>, readInt32Vector), | 
 | 200 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<int64_t>>, readInt64Vector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 201 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<int64_t>>, readInt64Vector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 202 |     // PARCEL_READ_WITH_STATUS(std::vector<int64_t>, readInt64Vector), | 
 | 203 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<uint64_t>>, readUint64Vector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 204 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<uint64_t>>, readUint64Vector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 205 |     // PARCEL_READ_WITH_STATUS(std::vector<uint64_t>, readUint64Vector), | 
 | 206 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<float>>, readFloatVector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 207 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<float>>, readFloatVector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 208 |     // PARCEL_READ_WITH_STATUS(std::vector<float>, readFloatVector), | 
 | 209 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<double>>, readDoubleVector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 210 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<double>>, readDoubleVector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 211 |     // PARCEL_READ_WITH_STATUS(std::vector<double>, readDoubleVector), | 
 | 212 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<bool>>, readBoolVector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 213 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<bool>>, readBoolVector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 214 |     // PARCEL_READ_WITH_STATUS(std::vector<bool>, readBoolVector), | 
 | 215 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<char16_t>>, readCharVector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 216 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<char16_t>>, readCharVector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 217 |     // PARCEL_READ_WITH_STATUS(std::vector<char16_t>, readCharVector), | 
 | 218 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<std::unique_ptr<android::String16>>>, readString16Vector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 219 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<std::optional<android::String16>>>, readString16Vector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 220 |     // PARCEL_READ_WITH_STATUS(std::vector<android::String16>, readString16Vector), | 
 | 221 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<std::unique_ptr<std::string>>>, readUtf8VectorFromUtf16Vector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 222 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<std::optional<std::string>>>, readUtf8VectorFromUtf16Vector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 223 |     // PARCEL_READ_WITH_STATUS(std::vector<std::string>, readUtf8VectorFromUtf16Vector), | 
 | 224 |  | 
| Steven Moreland | 6d81393 | 2019-09-30 15:31:35 -0700 | [diff] [blame] | 225 |     [] (const android::Parcel& p, uint8_t /*len*/) { | 
 | 226 |         FUZZ_LOG() << "about to read flattenable"; | 
 | 227 |         ExampleFlattenable f; | 
 | 228 |         status_t status = p.read(f); | 
 | 229 |         FUZZ_LOG() << "read flattenable: " << status; | 
 | 230 |     }, | 
 | 231 |     [] (const android::Parcel& p, uint8_t /*len*/) { | 
 | 232 |         FUZZ_LOG() << "about to read lite flattenable"; | 
 | 233 |         ExampleLightFlattenable f; | 
 | 234 |         status_t status = p.read(f); | 
 | 235 |         FUZZ_LOG() << "read lite flattenable: " << status; | 
 | 236 |     }, | 
| Steven Moreland | 7c7c648 | 2019-09-30 12:32:02 -0700 | [diff] [blame] | 237 |  | 
 | 238 |     // TODO(b/131868573): can force read of arbitrarily sized vector | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 239 |     // TODO: resizeOutVector | 
 | 240 |  | 
 | 241 |     PARCEL_READ_NO_STATUS(int32_t, readExceptionCode), | 
| Steven Moreland | 7c7c648 | 2019-09-30 12:32:02 -0700 | [diff] [blame] | 242 |     [] (const android::Parcel& p, uint8_t /*len*/) { | 
 | 243 |         FUZZ_LOG() << "about to readNativeHandle"; | 
 | 244 |         native_handle_t* t = p.readNativeHandle(); | 
 | 245 |         FUZZ_LOG() << "readNativeHandle: " << t; | 
 | 246 |         if (t != nullptr) { | 
 | 247 |             FUZZ_LOG() << "about to free readNativeHandle"; | 
 | 248 |             native_handle_close(t); | 
 | 249 |             native_handle_delete(t); | 
 | 250 |             FUZZ_LOG() << "readNativeHandle freed"; | 
 | 251 |         } | 
 | 252 |     }, | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 253 |     PARCEL_READ_NO_STATUS(int, readFileDescriptor), | 
 | 254 |     PARCEL_READ_NO_STATUS(int, readParcelFileDescriptor), | 
 | 255 |     PARCEL_READ_WITH_STATUS(android::base::unique_fd, readUniqueFileDescriptor), | 
 | 256 |  | 
 | 257 |     // TODO(b/131868573): can force read of arbitrarily sized vector | 
 | 258 |     // PARCEL_READ_WITH_STATUS(std::unique_ptr<std::vector<android::base::unique_fd>>, readUniqueFileDescriptorVector), | 
| Jooyung Han | 3750600 | 2020-02-18 10:57:44 +0900 | [diff] [blame] | 259 |     // PARCEL_READ_WITH_STATUS(std::optional<std::vector<android::base::unique_fd>>, readUniqueFileDescriptorVector), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 260 |     // PARCEL_READ_WITH_STATUS(std::vector<android::base::unique_fd>, readUniqueFileDescriptorVector), | 
 | 261 |  | 
 | 262 |     [] (const android::Parcel& p, uint8_t len) { | 
 | 263 |         FUZZ_LOG() << "about to readBlob"; | 
 | 264 |         ::android::Parcel::ReadableBlob blob; | 
 | 265 |         status_t status = p.readBlob(len, &blob); | 
 | 266 |         FUZZ_LOG() << "readBlob status: " << status; | 
 | 267 |     }, | 
| Steven Moreland | 7c7c648 | 2019-09-30 12:32:02 -0700 | [diff] [blame] | 268 |     [] (const android::Parcel& p, uint8_t options) { | 
 | 269 |         FUZZ_LOG() << "about to readObject"; | 
 | 270 |         bool nullMetaData = options & 0x1; | 
 | 271 |         const void* obj = static_cast<const void*>(p.readObject(nullMetaData)); | 
 | 272 |         FUZZ_LOG() << "readObject: " << obj; | 
 | 273 |     }, | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 274 |     PARCEL_READ_NO_STATUS(uid_t, readCallingWorkSourceUid), | 
 | 275 |     PARCEL_READ_NO_STATUS(size_t, getBlobAshmemSize), | 
 | 276 |     PARCEL_READ_NO_STATUS(size_t, getOpenAshmemSize), | 
| Steven Moreland | d115f83 | 2020-09-22 21:01:35 +0000 | [diff] [blame] | 277 |  | 
 | 278 |     // additional parcelable objects defined in libbinder | 
 | 279 |     [] (const ::android::Parcel& p, uint8_t data) { | 
 | 280 |         using ::android::os::ParcelableHolder; | 
 | 281 |         using ::android::Parcelable; | 
 | 282 |         FUZZ_LOG() << "about to read ParcelableHolder using readParcelable with status"; | 
 | 283 |         Parcelable::Stability stability = Parcelable::Stability::STABILITY_LOCAL; | 
 | 284 |         if ( (data & 1) == 1 ) { | 
 | 285 |             stability = Parcelable::Stability::STABILITY_VINTF; | 
 | 286 |         } | 
 | 287 |         ParcelableHolder t = ParcelableHolder(stability); | 
 | 288 |         status_t status = p.readParcelable(&t); | 
 | 289 |         FUZZ_LOG() << "ParcelableHolder status: " << status; | 
 | 290 |     }, | 
 | 291 |     PARCEL_READ_WITH_STATUS(android::os::PersistableBundle, readParcelable), | 
| Steven Moreland | 46e0da7 | 2019-09-05 15:52:02 -0700 | [diff] [blame] | 292 | }; | 
| Steven Moreland | 9cb1e6a | 2019-10-15 17:20:51 -0700 | [diff] [blame] | 293 | // clang-format on | 
| Jooyung Han | ceae53e | 2020-11-18 12:17:50 +0900 | [diff] [blame] | 294 | #pragma clang diagnostic pop |