• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_data_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 "mock_iall_in_one_executor_fuzzer.h"
28 #include "mock_icollector_executor_fuzzer.h"
29 
30 #include "i_inputer_data_impl.h"
31 #include "pin_auth_hdi.h"
32 
33 #define LOG_TAG "PIN_AUTH_SA"
34 
35 #undef private
36 
37 using namespace std;
38 using namespace OHOS::UserIam::Common;
39 
40 namespace OHOS {
41 namespace UserIam {
42 namespace PinAuth {
43 namespace {
44 const uint32_t SCHEDULE_ID = 123;
45 auto executorProxy_ = sptr<IAllInOneExecutor>(new (std::nothrow) MockIAllInOneExecutorFuzzer());
46 auto hdi_ = Common::MakeShared<PinAuthAllInOneHdi>(executorProxy_);
47 auto g_service = new (std::nothrow) IInputerDataImpl(SCHEDULE_ID, hdi_);
48 
FuzzRegisterInputer(Parcel & parcel)49 void FuzzRegisterInputer(Parcel &parcel)
50 {
51     IAM_LOGI("begin");
52     int32_t authSubType = parcel.ReadInt32();
53     std::vector<uint8_t> data;
54     uint32_t pinLength = parcel.ReadUint32();
55     int32_t errorCode = parcel.ReadInt32();
56     FillFuzzUint8Vector(parcel, data);
57     if (g_service != nullptr) {
58         g_service->OnSetData(authSubType, data, pinLength, errorCode);
59     }
60     IAM_LOGI("end");
61 }
62 
63 using FuzzFunc = decltype(FuzzRegisterInputer);
64 FuzzFunc *g_fuzzFuncs[] = {FuzzRegisterInputer};
65 
InputerDataFuzzTest(const uint8_t * data,size_t size)66 void InputerDataFuzzTest(const uint8_t *data, size_t size)
67 {
68     Parcel parcel;
69     parcel.WriteBuffer(data, size);
70     parcel.RewindRead(0);
71     uint32_t index = parcel.ReadUint32() % (sizeof(g_fuzzFuncs) / sizeof(FuzzFunc *));
72     auto fuzzFunc = g_fuzzFuncs[index];
73     fuzzFunc(parcel);
74     return;
75 }
76 } // namespace
77 } // namespace PinAuth
78 } // namespace UserIam
79 } // namespace OHOS
80 
81 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)82 extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
83 {
84     OHOS::UserIam::PinAuth::InputerDataFuzzTest(data, size);
85     return 0;
86 }