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 
17 #include <android/binder_auto_utils.h>
18 #include <vector>
19 
20 #include <android/binder_parcel.h>
21 #include "parcel_fuzzer.h"
22 
23 // libbinder_ndk doesn't export this header which breaks down its API for NDK
24 // and APEX users, but we need access to it to fuzz.
25 #include "../ndk/parcel_internal.h"
26 
27 class NdkParcelAdapter {
28 public:
NdkParcelAdapter()29     NdkParcelAdapter() : mParcel(new AParcel(nullptr /*binder*/)) {}
30 
aParcel()31     const AParcel* aParcel() const { return mParcel.get(); }
aParcel()32     AParcel* aParcel() { return mParcel.get(); }
33 
dataSize()34     size_t dataSize() const { return aParcel()->get()->dataSize(); }
dataAvail()35     size_t dataAvail() const { return aParcel()->get()->dataAvail(); }
dataPosition()36     size_t dataPosition() const { return aParcel()->get()->dataPosition(); }
dataCapacity()37     size_t dataCapacity() const { return aParcel()->get()->dataCapacity(); }
setData(const uint8_t * buffer,size_t len)38     android::status_t setData(const uint8_t* buffer, size_t len) {
39         return aParcel()->get()->setData(buffer, len);
40     }
41 
42 private:
43     ndk::ScopedAParcel mParcel;
44 };
45 
46 extern std::vector<ParcelRead<NdkParcelAdapter>> BINDER_NDK_PARCEL_READ_FUNCTIONS;
47