• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2023 Huawei Device Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 
16 #include "securec.h"
17 #include <cstdint>
18 #include <cstdlib>
19 #include <memory>
20 
21 #include "thermal_interface_impl.h"
22 #include "v1_1/ithermal_callback.h"
23 #include "v1_1/ithermal_interface.h"
24 #include "v1_1/thermal_interface_stub.h"
25 #include "v1_1/thermal_types.h"
26 
27 using namespace OHOS::HDI;
28 using namespace OHOS::HDI::Thermal::V1_1;
29 using namespace std;
30 
31 namespace OHOS {
32 namespace HDI {
33 namespace Thermal {
34 namespace V1_1 {
35 namespace {
36 const int32_t REWIND_READ_DATA = 0;
37 shared_ptr<ThermalInterfaceStub> g_fuzzService = nullptr;
38 } // namespace
39 
ThermalStubFuzzTest(const uint8_t * data,size_t size)40 static void ThermalStubFuzzTest(const uint8_t *data, size_t size)
41 {
42     uint32_t code;
43     if (size < sizeof(code)) {
44         return;
45     }
46     if (memcpy_s(&code, sizeof(code), data, sizeof(code)) != EOK) {
47         return;
48     }
49 
50     MessageParcel datas;
51     datas.WriteInterfaceToken(IThermalInterface::GetDescriptor());
52     datas.WriteBuffer(data, size);
53     datas.RewindRead(REWIND_READ_DATA);
54     MessageParcel reply;
55     MessageOption option;
56     if (g_fuzzService == nullptr) {
57         g_fuzzService = make_shared<ThermalInterfaceStub>(new ThermalInterfaceImpl());
58     }
59     g_fuzzService->OnRemoteRequest(code, datas, reply, option);
60 }
61 } // namespace V1_1
62 } // namespace Thermal
63 } // namespace HDI
64 } // namespace OHOS
65 
66 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)67 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
68 {
69     /* Run your code on data */
70     OHOS::HDI::Thermal::V1_1::ThermalStubFuzzTest(data, size);
71     return 0;
72 }
73