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 "separateconference_fuzzer.h"
17
18 #include <cstddef>
19 #include <cstdint>
20
21 #define private public
22 #include "addcellularcalltoken_fuzzer.h"
23 #include "cs_control.h"
24 #include "securec.h"
25 #include "system_ability_definition.h"
26
27 using namespace OHOS::Telephony;
28 namespace OHOS {
29 constexpr int32_t SLOT_NUM = 2;
30 constexpr int32_t VEDIO_STATE_NUM = 2;
31 constexpr size_t MAX_NUMBER_LEN = 99;
32
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)33 void DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
34 {
35 if (data == nullptr || size == 0) {
36 return;
37 }
38
39 auto cSControl = std::make_shared<CSControl>();
40 int32_t slotId = static_cast<int32_t>(size % SLOT_NUM);
41 int32_t callId = static_cast<int32_t>(size);
42 int32_t accountId = static_cast<int32_t>(size);
43 int32_t videoState = static_cast<int32_t>(size % VEDIO_STATE_NUM);
44 int32_t index = static_cast<int32_t>(size);
45 CallSupplementType type = CallSupplementType::TYPE_DEFAULT;
46 std::string splitString(reinterpret_cast<const char *>(data), size);
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 cSControl->DialCdma(callInfo);
64 cSControl->DialGsm(callInfo);
65 cSControl->HangUp(callInfo, type);
66 cSControl->Answer(callInfo);
67 cSControl->Reject(callInfo);
68 cSControl->HoldCall(slotId);
69 cSControl->UnHoldCall(slotId);
70 cSControl->SwitchCall(slotId);
71 cSControl->SeparateConference(slotId, splitString, index);
72 cSControl->CombineConference(slotId);
73 cSControl->HangUpAllConnection(slotId);
74 return;
75 }
76 } // namespace OHOS
77
78 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)79 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
80 {
81 OHOS::AddCellularCallTokenFuzzer token;
82 /* Run your code on data */
83 OHOS::DoSomethingInterestingWithMyAPI(data, size);
84 return 0;
85 }
86