1 /*
2 * Copyright (c) 2023-2024 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 "inputer_set_data_stub_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20
21 #include "parcel.h"
22
23 #include "iam_fuzz_test.h"
24 #include "iam_logger.h"
25 #include "iam_ptr.h"
26
27 #include "i_inputer_data_impl.h"
28 #include "pin_auth_hdi.h"
29
30 #define LOG_TAG "PIN_AUTH_SA"
31
32 #undef private
33
34 using namespace std;
35 using namespace OHOS::UserIam::Common;
36
37 namespace OHOS {
38 namespace UserIam {
39 namespace PinAuth {
40 namespace {
41
42 constexpr uint32_t SCHEDULE_ID = 123;
43 constexpr uint32_t INPUTER_SET_DATA_CODE_MIN = 1;
44 constexpr uint32_t INPUTER_SET_DATA_CODE_MAX = 1;
45 const std::u16string INPUTER_SET_DATA_INTERFACE_TOKEN = u"ohos.PinAuth.InputerSetData";
46
InputerSetDataStubFuzzTest(const uint8_t * rawData,size_t size)47 bool InputerSetDataStubFuzzTest(const uint8_t *rawData, size_t size)
48 {
49 IAM_LOGI("start");
50 if (rawData == nullptr) {
51 return false;
52 }
53
54 sptr<IAllInOneExecutor> executorProxy(nullptr);
55 std::shared_ptr<PinAuthAllInOneHdi> pinAuthExecutorHdi_ = Common::MakeShared<PinAuthAllInOneHdi>(executorProxy);
56 IInputerDataImpl iInputerDataImpl(SCHEDULE_ID, pinAuthExecutorHdi_);
57 for (uint32_t code = INPUTER_SET_DATA_CODE_MIN; code <= INPUTER_SET_DATA_CODE_MAX; code++) {
58 MessageParcel data;
59 MessageParcel reply;
60 MessageOption optionSync = MessageOption::TF_SYNC;
61 MessageOption optionAsync = MessageOption::TF_ASYNC;
62 // Sync
63 data.WriteInterfaceToken(INPUTER_SET_DATA_INTERFACE_TOKEN);
64 data.WriteBuffer(rawData, size);
65 data.RewindRead(0);
66 (void)iInputerDataImpl.OnRemoteRequest(code, data, reply, optionSync);
67 // Async
68 data.WriteInterfaceToken(INPUTER_SET_DATA_INTERFACE_TOKEN);
69 data.WriteBuffer(rawData, size);
70 data.RewindRead(0);
71 (void)iInputerDataImpl.OnRemoteRequest(code, data, reply, optionAsync);
72 }
73 return true;
74 }
75 } // namespace
76 } // namespace PinAuth
77 } // namespace UserIam
78 } // namespace OHOS
79
80 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)81 extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
82 {
83 OHOS::UserIam::PinAuth::InputerSetDataStubFuzzTest(data, size);
84 return 0;
85 }
86