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 "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
29 #define LOG_LABEL UserIam::Common::LABEL_PIN_AUTH_SA
30
31 #undef private
32
33 using namespace std;
34 using namespace OHOS::UserIam::Common;
35
36 namespace OHOS {
37 namespace UserIam {
38 namespace PinAuth {
39 namespace {
40
41 constexpr uint32_t SCHEDULE_ID = 123;
42 constexpr uint32_t INPUTER_SET_DATA_CODE_MIN = 1;
43 constexpr uint32_t INPUTER_SET_DATA_CODE_MAX = 1;
44 const std::u16string INPUTER_SET_DATA_INTERFACE_TOKEN = u"ohos.PinAuth.InputerSetData";
45
InputerSetDataStubFuzzTest(const uint8_t * rawData,size_t size)46 bool InputerSetDataStubFuzzTest(const uint8_t *rawData, size_t size)
47 {
48 IAM_LOGI("start");
49 if (rawData == nullptr) {
50 return false;
51 }
52
53 sptr<HDI::PinAuth::V1_1::IExecutor> executorProxy(nullptr);
54 std::shared_ptr<PinAuthExecutorHdi> pinAuthExecutorHdi_ = Common::MakeShared<PinAuthExecutorHdi>(executorProxy);
55 IInputerDataImpl iInputerDataImpl(SCHEDULE_ID, pinAuthExecutorHdi_);
56 for (uint32_t code = INPUTER_SET_DATA_CODE_MIN; code <= INPUTER_SET_DATA_CODE_MAX; code++) {
57 MessageParcel data;
58 MessageParcel reply;
59 MessageOption optionSync = MessageOption::TF_SYNC;
60 MessageOption optionAsync = MessageOption::TF_ASYNC;
61 // Sync
62 data.WriteInterfaceToken(INPUTER_SET_DATA_INTERFACE_TOKEN);
63 data.WriteBuffer(rawData, size);
64 data.RewindRead(0);
65 (void)iInputerDataImpl.OnRemoteRequest(code, data, reply, optionSync);
66 // Async
67 data.WriteInterfaceToken(INPUTER_SET_DATA_INTERFACE_TOKEN);
68 data.WriteBuffer(rawData, size);
69 data.RewindRead(0);
70 (void)iInputerDataImpl.OnRemoteRequest(code, data, reply, optionAsync);
71 }
72 return true;
73 }
74 } // namespace
75 } // namespace PinAuth
76 } // namespace UserIam
77 } // namespace OHOS
78
79 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)80 extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
81 {
82 OHOS::UserIam::PinAuth::InputerSetDataStubFuzzTest(data, size);
83 return 0;
84 }
85