1 /*
2 * Copyright (c) 2025 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 "bmsverifymanagerhost_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <fuzzer/FuzzedDataProvider.h>
21
22 #include "bms_fuzztest_util.h"
23 #include "securec.h"
24 #include "verify_manager_stub.h"
25
26 using namespace OHOS::AppExecFwk;
27 using namespace OHOS::AppExecFwk::BMSFuzzTestUtil;
28 namespace OHOS {
29 constexpr size_t MESSAGE_SIZE = 3;
30
31 class MockVerifyManagerStub : public VerifyManagerStub {
32 public:
CallbackEnter(uint32_t code)33 int32_t CallbackEnter(uint32_t code) override
34 {
35 return 0;
36 }
37
CallbackExit(uint32_t code,int32_t result)38 int32_t CallbackExit(uint32_t code, int32_t result) override
39 {
40 return 0;
41 }
42
Verify(const std::vector<std::string> & abcPaths,int32_t & funcResult)43 ErrCode Verify(const std::vector<std::string>& abcPaths, int32_t& funcResult) override
44 {
45 return ERR_OK;
46 }
47
DeleteAbc(const std::string & path,int32_t & funcResult)48 ErrCode DeleteAbc(const std::string& path, int32_t& funcResult) override
49 {
50 return ERR_OK;
51 }
52 };
53
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)54 bool DoSomethingInterestingWithMyAPI(const uint8_t* data, size_t size)
55 {
56 FuzzedDataProvider fdp(data, size);
57 uint32_t code = fdp.ConsumeIntegralInRange<uint32_t>(0, MESSAGE_SIZE);
58 MessageParcel datas;
59 std::u16string descriptor = MockVerifyManagerStub::GetDescriptor();
60 datas.WriteInterfaceToken(descriptor);
61 datas.WriteBuffer(data, size);
62 datas.RewindRead(0);
63 MessageParcel reply;
64 MessageOption option;
65 MockVerifyManagerStub verifyManagerStub;
66 verifyManagerStub.OnRemoteRequest(code, datas, reply, option);
67 return true;
68 }
69 }
70
71 // Fuzzer entry point.
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)72 extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size)
73 {
74 OHOS::DoSomethingInterestingWithMyAPI(data, size);
75 return 0;
76 }