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