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 "reporthangupinfo_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20 #include <cstdio>
21
22 #define private public
23 #include "addcellularcalltoken_fuzzer.h"
24 #include "ims_control.h"
25 #include "satellite_control.h"
26 #include "securec.h"
27 #include "system_ability_definition.h"
28
29 using namespace OHOS::Telephony;
30 namespace OHOS {
31 constexpr int32_t SLOT_NUM = 2;
32 constexpr int32_t VEDIO_STATE_NUM = 2;
33 constexpr size_t MAX_NUMBER_LEN = 99;
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
41 auto iMSControl = std::make_shared<IMSControl>();
42 int32_t slotId = static_cast<int32_t>(size % SLOT_NUM);
43 int32_t callId = static_cast<int32_t>(size);
44 int32_t accountId = static_cast<int32_t>(size);
45 int32_t videoState = static_cast<int32_t>(size % VEDIO_STATE_NUM);
46 int32_t index = static_cast<int32_t>(size);
47 CallSupplementType type = CallSupplementType::TYPE_DEFAULT;
48 std::string telNum = "000000000";
49 std::string tempNum(reinterpret_cast<const char *>(data), size);
50 if (strlen(tempNum.c_str()) <= MAX_NUMBER_LEN) {
51 telNum = tempNum;
52 }
53 size_t length = strlen(telNum.c_str()) + 1;
54 CellularCallInfo callInfo;
55 callInfo.slotId = slotId;
56 callInfo.callId = callId;
57 callInfo.accountId = accountId;
58 callInfo.videoState = videoState;
59 callInfo.index = index;
60 callInfo.callType = CallType::TYPE_CS;
61 if (strcpy_s(callInfo.phoneNum, length, telNum.c_str()) != EOK) {
62 return;
63 }
64 bool isEcc = false;
65 iMSControl->Dial(callInfo, isEcc);
66 iMSControl->HangUp(callInfo, type);
67 iMSControl->Answer(callInfo);
68 iMSControl->Reject(callInfo);
69 iMSControl->HoldCall(slotId);
70 iMSControl->UnHoldCall(slotId);
71 iMSControl->SwitchCall(slotId);
72 iMSControl->ReportHangUpInfo(slotId);
73
74 auto satelliteControl = std::make_shared<SatelliteControl>();
75 callInfo.callType = CallType::TYPE_SATELLITE;
76 satelliteControl->Dial(callInfo, isEcc);
77 satelliteControl->HangUp(callInfo, type);
78 satelliteControl->Answer(callInfo);
79 satelliteControl->Reject(callInfo);
80 satelliteControl->HoldCall(slotId);
81 satelliteControl->UnHoldCall(slotId);
82 satelliteControl->SwitchCall(slotId);
83 satelliteControl->ReportHangUpInfo(slotId);
84 return;
85 }
86 } // namespace OHOS
87
88 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)89 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
90 {
91 OHOS::AddCellularCallTokenFuzzer token;
92 /* Run your code on data */
93 OHOS::DoSomethingInterestingWithMyAPI(data, size);
94 return 0;
95 }
96