1 /*
2  * Copyright (C) 2023 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 #define private public
16 #define protected public
17 #include "satellitecallrequest_fuzzer.h"
18 
19 #include <cstddef>
20 #include <cstdint>
21 
22 #include "addcellularcalltoken_fuzzer.h"
23 #include "cellular_call_connection_satellite.h"
24 #include "cellular_call_data_struct.h"
25 #include "system_ability_definition.h"
26 
27 using namespace OHOS::Telephony;
28 namespace OHOS {
29 constexpr int32_t SLOT_NUM = 2;
30 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)31 void DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
32 {
33     if (data == nullptr || size == 0) {
34         return;
35     }
36 
37     auto cellularCallConnectionSatellite = std::make_unique<CellularCallConnectionSatellite>().release();
38     std::string phoneNum(reinterpret_cast<const char *>(data), size);
39     int32_t slotId = static_cast<int32_t>(size % SLOT_NUM);
40     int64_t lastCallsDataFlag = static_cast<int64_t>(size);
41     DialRequestStruct dialRequest;
42     dialRequest.phoneNum = phoneNum;
43     cellularCallConnectionSatellite->DialRequest(slotId, dialRequest);
44     cellularCallConnectionSatellite->HangUpRequest(slotId);
45     cellularCallConnectionSatellite->AnswerRequest(slotId);
46     cellularCallConnectionSatellite->RejectRequest(slotId);
47     cellularCallConnectionSatellite->GetSatelliteCallsDataRequest(slotId, lastCallsDataFlag);
48     cellularCallConnectionSatellite->GetCallFailReasonRequest(slotId);
49     return;
50 }
51 } // namespace OHOS
52 
53 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)54 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
55 {
56     OHOS::AddCellularCallTokenFuzzer token;
57     /* Run your code on data */
58     OHOS::DoSomethingInterestingWithMyAPI(data, size);
59     return 0;
60 }
61