1 /*
2  * Copyright (c) 2022 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 "updatesmsicc_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 #define private public
22 #include "addcoreservicetoken_fuzzer.h"
23 #include "common_event_manager.h"
24 #include "common_event_support.h"
25 #include "event_handler.h"
26 #include "event_runner.h"
27 #include "sim_sms_controller.h"
28 #include "system_ability_definition.h"
29 #include "tel_ril_manager.h"
30 
31 using namespace OHOS::Telephony;
32 namespace OHOS {
33 bool g_flag = false;
34 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)35 void DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
36 {
37     if (data == nullptr || size == 0) {
38         return;
39     }
40     if (g_flag) {
41         return;
42     }
43     g_flag = true;
44 
45     auto telRilManager_ = std::make_shared<TelRilManager>();
46     auto stateManager_ = std::make_shared<SimStateManager>(telRilManager_);
47     auto simSmsController = std::make_shared<SimSmsController>(stateManager_);
48     std::int32_t eventId = static_cast<int32_t>(size);
49     std::unique_ptr<uint8_t> object = std::make_unique<uint8_t>(*data);
50     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(eventId, object);
51     simSmsController->BuildCallerInfo(eventId);
52     simSmsController->IsCdmaCardType();
53     simSmsController->ProcessEvent(event);
54 }
55 } // namespace OHOS
56 
57 /* Fuzzer entry point */
LLVMFuzzerInitialize(int * argc,char *** argv)58 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
59 {
60     OHOS::AddCoreServiceTokenFuzzer token;
61     return 0;
62 }
63 
64 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)65 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
66 {
67     /* Run your code on data */
68     OHOS::DoSomethingInterestingWithMyAPI(data, size);
69     return 0;
70 }
71