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