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 "rejectcall_fuzzer.h" 17 18#include <cstddef> 19#include <cstdint> 20#define private public 21#include "addcalltoken_fuzzer.h" 22#include "call_manager_service_stub.h" 23 24using namespace OHOS::Telephony; 25namespace OHOS { 26constexpr int32_t SLOT_NUM = 2; 27constexpr int32_t CHOICE_NUM = 2; 28 29void RejectCall(const uint8_t *data, size_t size) 30{ 31 if (!IsServiceInited()) { 32 return; 33 } 34 35 int32_t slotId = static_cast<int32_t>(size % SLOT_NUM); 36 int32_t rejectWithMessage = static_cast<int32_t>(size % CHOICE_NUM); 37 std::string message(reinterpret_cast<const char *>(data), size); 38 MessageParcel dataMessageParcel; 39 dataMessageParcel.WriteInt32(slotId); 40 dataMessageParcel.WriteInt32(rejectWithMessage); 41 dataMessageParcel.WriteString16(Str8ToStr16(message)); 42 dataMessageParcel.RewindRead(0); 43 MessageParcel reply; 44 DelayedSingleton<CallManagerService>::GetInstance()->OnRejectCall(dataMessageParcel, reply); 45} 46 47void DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) 48{ 49 if (data == nullptr || size == 0) { 50 return; 51 } 52 53 RejectCall(data, size); 54} 55} // namespace OHOS 56 57/* Fuzzer entry point */ 58extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) 59{ 60 OHOS::AddCallTokenFuzzer token; 61 /* Run your code on data */ 62 OHOS::DoSomethingInterestingWithMyAPI(data, size); 63 return 0; 64} 65