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 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 int32_t roaming = static_cast<int32_t>(*data % BOOL_NUM);
46 int32_t offset = 0;
47 int32_t response = static_cast<int32_t>(*data + offset);
48 offset += sizeof(int32_t);
49 std::int32_t eventId = static_cast<int32_t>(*data + offset);
50 offset += sizeof(int32_t);
51 std::int64_t refId = static_cast<int64_t>(*data + offset);
52 std::string operatorNum(reinterpret_cast<const char *>(data), size);
53 std::string mailName(reinterpret_cast<const char *>(data), size);
54 std::string mailNumber(reinterpret_cast<const char *>(data), size);
55 AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(eventId, refId);
56 auto telRilManager_ = std::make_shared<TelRilManager>();
57 auto stateManager_ = std::make_shared<SimStateManager>(telRilManager_);
58 auto ruimFile = std::make_shared<RuimFile>(stateManager_);
59 ruimFile->ObtainSpnCondition(roaming, operatorNum);
60 ruimFile->UpdateVoiceMail(mailName, mailNumber);
61 ruimFile->ObtainIsoCountryCode();
62 ruimFile->ObtainSid();
63 ruimFile->ProcessGetIccidDone(event);
64 ruimFile->ProcessGetSubscriptionDone(event);
65 ruimFile->ProcessGetImsiDone(event);
66 ruimFile->ProcessFileLoaded(response);
67 ruimFile->ObtainNid();
68 ruimFile->ObtainCsimSpnDisplayCondition();
69 ruimFile->ObtainNAI();
70 ruimFile->ObtainMdn();
71 return;
72 }
73 } // namespace OHOS
74
75 /* Fuzzer entry point */
LLVMFuzzerInitialize(int * argc,char *** argv)76 extern "C" int LLVMFuzzerInitialize(int *argc, char ***argv)
77 {
78 OHOS::AddCoreServiceTokenFuzzer token;
79 return 0;
80 }
81
82 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)83 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
84 {
85 /* Run your code on data */
86 OHOS::DoSomethingInterestingWithMyAPI(data, size);
87 return 0;
88 }
89