• 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 "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 "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 const uint32_t SCHEDULE_ID = 123;
41 sptr<HDI::PinAuth::V1_1::IExecutor> executorProxy(nullptr);
42 std::shared_ptr<PinAuthExecutorHdi> pinAuthExecutorHdi_ = Common::MakeShared<PinAuthExecutorHdi>(executorProxy);
43 auto g_service = new (std::nothrow) IInputerDataImpl(SCHEDULE_ID, pinAuthExecutorHdi_);
44 
FuzzRegisterInputer(Parcel & parcel)45 void FuzzRegisterInputer(Parcel &parcel)
46 {
47     IAM_LOGI("begin");
48     int32_t authSubType = parcel.ReadInt32();
49     std::vector<uint8_t> data;
50     FillFuzzUint8Vector(parcel, data);
51     if (g_service != nullptr) {
52         g_service->OnSetData(authSubType, data);
53     }
54     IAM_LOGI("end");
55 }
56 
57 using FuzzFunc = decltype(FuzzRegisterInputer);
58 FuzzFunc *g_fuzzFuncs[] = {FuzzRegisterInputer};
59 
InputerDataFuzzTest(const uint8_t * data,size_t size)60 void InputerDataFuzzTest(const uint8_t *data, size_t size)
61 {
62     Parcel parcel;
63     parcel.WriteBuffer(data, size);
64     parcel.RewindRead(0);
65     uint32_t index = parcel.ReadUint32() % (sizeof(g_fuzzFuncs) / sizeof(FuzzFunc *));
66     auto fuzzFunc = g_fuzzFuncs[index];
67     fuzzFunc(parcel);
68     return;
69 }
70 } // namespace
71 } // namespace PinAuth
72 } // namespace UserIam
73 } // namespace OHOS
74 
75 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)76 extern "C" int32_t LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
77 {
78     OHOS::UserIam::PinAuth::InputerDataFuzzTest(data, size);
79     return 0;
80 }