• 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 "updatevoicemail_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 #define private public
22 #define protected public
23 #include "addcoreservicetoken_fuzzer.h"
24 #include "event_runner.h"
25 #include "napi_util.h"
26 #include "ruim_file.h"
27 #include "system_ability_definition.h"
28 #include "tel_ril_manager.h"
29 
30 using namespace OHOS::Telephony;
31 namespace OHOS {
32 constexpr int32_t BOOL_NUM = 2;
33 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)34 void DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
35 {
36     if (data == nullptr || size == 0) {
37         return;
38     }
39 
40     int32_t roaming = static_cast<int32_t>(size % BOOL_NUM);
41     int32_t response = static_cast<int32_t>(size % BOOL_NUM);
42     std::int32_t eventId = static_cast<int32_t>(size);
43     std::int64_t refId = static_cast<int64_t>(size);
44     std::string operatorNum(reinterpret_cast<const char *>(data), size);
45     std::string mailName(reinterpret_cast<const char *>(data), size);
46     std::string mailNumber(reinterpret_cast<const char *>(data), size);
47     AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(eventId, refId);
48     auto telRilManager_ = std::make_shared<TelRilManager>();
49     auto stateManager_ = std::make_shared<SimStateManager>(telRilManager_);
50     auto eventLoopRecord_ = AppExecFwk::EventRunner::Create("IccFile");
51     auto ruimFile = std::make_shared<RuimFile>(eventLoopRecord_, stateManager_);
52     ruimFile->ObtainSpnCondition(roaming, operatorNum);
53     ruimFile->UpdateVoiceMail(mailName, mailNumber);
54     ruimFile->ObtainIsoCountryCode();
55     ruimFile->ObtainSid();
56     ruimFile->ProcessGetIccidDone(event);
57     ruimFile->ProcessGetSubscriptionDone(event);
58     ruimFile->ProcessGetImsiDone(event);
59     ruimFile->ProcessFileLoaded(response);
60     ruimFile->ObtainNid();
61     ruimFile->ObtainCsimSpnDisplayCondition();
62     ruimFile->ObtainNAI();
63     ruimFile->ObtainMdn();
64     return;
65 }
66 } // namespace OHOS
67 
68 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)69 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
70 {
71     OHOS::AddCoreServiceTokenFuzzer token;
72     /* Run your code on data */
73     OHOS::DoSomethingInterestingWithMyAPI(data, size);
74     return 0;
75 }
76