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 "setorupdatecallreportinfo_fuzzer.h"
17 
18 #include <cstddef>
19 #include <cstdint>
20 
21 #include "addcellularcalltoken_fuzzer.h"
22 #include "base_connection.h"
23 #include "securec.h"
24 #include "system_ability_definition.h"
25 
26 using namespace OHOS::Telephony;
27 namespace OHOS {
28 constexpr int32_t SLOT_NUM = 2;
29 constexpr int32_t BOOL_NUM = 2;
30 constexpr size_t MAX_NUMBER_LEN = 99;
31 
DoSomethingInterestingWithMyAPI(const uint8_t * data,size_t size)32 void DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size)
33 {
34     if (data == nullptr || size == 0) {
35         return;
36     }
37 
38     auto baseConnection = std::make_shared<BaseConnection>();
39     int32_t accountId = static_cast<int32_t>(size % SLOT_NUM);
40     int32_t index = static_cast<int32_t>(size);
41     int32_t flag = static_cast<int32_t>(size % BOOL_NUM);
42     int32_t voiceDomain = static_cast<int32_t>(size % BOOL_NUM);
43     std::string phoneNum = "000000000";
44     std::string tempNum(reinterpret_cast<const char *>(data), size);
45     if (strlen(tempNum.c_str()) <= MAX_NUMBER_LEN) {
46         phoneNum = tempNum;
47     }
48     size_t length = strlen(phoneNum.c_str()) + 1;
49     CallReportInfo callReportInfo;
50     callReportInfo.index = index;
51     callReportInfo.accountId = accountId;
52     callReportInfo.callType = CallType::TYPE_CS;
53     callReportInfo.callMode = VideoStateType::TYPE_VIDEO;
54     callReportInfo.state = TelCallState::CALL_STATUS_ACTIVE;
55     callReportInfo.voiceDomain = voiceDomain;
56     if (strcpy_s(callReportInfo.accountNum, length, phoneNum.c_str()) != EOK) {
57         return;
58     }
59     baseConnection->SetOrUpdateCallReportInfo(callReportInfo);
60     baseConnection->GetStatus();
61     baseConnection->IsRingingState();
62     baseConnection->SetFlag(flag);
63     baseConnection->GetFlag();
64     baseConnection->SetIndex(index);
65     baseConnection->GetIndex();
66     return;
67 }
68 } // namespace OHOS
69 
70 /* Fuzzer entry point */
LLVMFuzzerTestOneInput(const uint8_t * data,size_t size)71 extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
72 {
73     OHOS::AddCellularCallTokenFuzzer token;
74     /* Run your code on data */
75     OHOS::DoSomethingInterestingWithMyAPI(data, size);
76     return 0;
77 }
78