• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 {
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)33 void DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
34 {
35     if (data == nullptr || size == 0) {
36         return;
37     }
38 
39     auto telRilManager_ = std::make_shared<TelRilManager>();
40     auto stateManager_ = std::make_shared<SimStateManager>(telRilManager_);
41     auto eventLoopSms_ = AppExecFwk::EventRunner::Create("simSmsController");
42     auto simSmsController = std::make_shared<SimSmsController>(eventLoopSms_, stateManager_);
43     std::int32_t eventId = static_cast<int32_t>(size);
44     std::unique_ptr<uint8_t> object = std::make_unique<uint8_t>(*data);
45     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(eventId, object);
46     simSmsController->BuildCallerInfo(eventId);
47     simSmsController->IsCdmaCardType();
48     simSmsController->ProcessEvent(event);
49 }
50 } // namespace OHOS
51 
52 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)53 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
54 {
55     OHOS::AddCoreServiceTokenFuzzer token;
56     /* Run your code on data */
57     OHOS::DoSomethingInterestingWithMyAPI(data, size);
58     return 0;
59 }
60