/* * Copyright (c) 2022 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ #include "dialcall_fuzzer.h" #include #include #define private public #include "addcalltoken_fuzzer.h" #include "call_ability_callback.h" using namespace OHOS::Telephony; namespace OHOS { constexpr int32_t SLOT_NUM = 2; constexpr int32_t ACTIVE_NUM = 2; constexpr int32_t VEDIO_STATE_NUM = 2; constexpr int32_t DIAL_SCENE_NUM = 3; constexpr int32_t DIAL_TYPE_NUM = 3; constexpr int32_t CALL_TYPE_NUM = 3; constexpr int32_t CALL_ID_NUM = 10; void OnRegisterVoipCallManagerCallback(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return; } MessageParcel dataMessageParcel; std::unique_ptr callbackWrap = std::make_unique(); if (callbackWrap == nullptr) { return; } dataMessageParcel.WriteRemoteObject(callbackWrap.release()->AsObject().GetRefPtr()); MessageParcel reply; DelayedSingleton::GetInstance()->OnRegisterVoipCallManagerCallback(dataMessageParcel, reply); } void OnRemoteRequest(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return; } MessageParcel dataMessageParcel; if (!dataMessageParcel.WriteInterfaceToken(CallManagerServiceStub::GetDescriptor())) { return; } dataMessageParcel.RewindRead(0); uint32_t code = static_cast(size); MessageParcel reply; MessageOption option; DelayedSingleton::GetInstance()->OnRemoteRequest(code, dataMessageParcel, reply, option); } int32_t OnRegisterCallBack(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return TELEPHONY_ERROR; } MessageParcel dataMessageParcel; std::unique_ptr callbackWrap = std::make_unique(); if (callbackWrap == nullptr) { return TELEPHONY_ERR_LOCAL_PTR_NULL; } dataMessageParcel.WriteRemoteObject(callbackWrap.release()->AsObject().GetRefPtr()); MessageParcel reply; return DelayedSingleton::GetInstance()->OnRegisterCallBack(dataMessageParcel, reply); } bool HasCall(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return TELEPHONY_ERROR; } MessageParcel dataParcel; dataParcel.WriteBuffer(data, size); dataParcel.RewindRead(0); MessageParcel reply; return DelayedSingleton::GetInstance()->OnHasCall(dataParcel, reply); } int32_t GetCallState(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return TELEPHONY_ERROR; } MessageParcel dataParcel; dataParcel.WriteBuffer(data, size); dataParcel.RewindRead(0); MessageParcel reply; return DelayedSingleton::GetInstance()->OnGetCallState(dataParcel, reply); } int32_t GetCallWaiting(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return TELEPHONY_ERROR; } int32_t slotId = static_cast(size % SLOT_NUM); MessageParcel dataParcel; dataParcel.WriteInt32(slotId); dataParcel.WriteBuffer(data, size); dataParcel.RewindRead(0); MessageParcel reply; return DelayedSingleton::GetInstance()->OnGetCallWaiting(dataParcel, reply); } bool IsRinging(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return false; } MessageParcel dataParcel; dataParcel.WriteBuffer(data, size); dataParcel.RewindRead(0); MessageParcel reply; return DelayedSingleton::GetInstance()->OnIsRinging(dataParcel, reply); } bool IsInEmergencyCall(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return false; } MessageParcel dataParcel; dataParcel.WriteBuffer(data, size); dataParcel.RewindRead(0); MessageParcel reply; return DelayedSingleton::GetInstance()->OnIsInEmergencyCall(dataParcel, reply); } int32_t DialCall(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return TELEPHONY_ERROR; } std::string number(reinterpret_cast(data), size); auto numberU16 = Str8ToStr16(number); int32_t accountId = static_cast(size % SLOT_NUM); int32_t videoState = static_cast(size % VEDIO_STATE_NUM); int32_t dialScene = static_cast(size % DIAL_SCENE_NUM); int32_t dialType = static_cast(size % DIAL_TYPE_NUM); int32_t callType = static_cast(size % CALL_TYPE_NUM); MessageParcel dataParcel; dataParcel.WriteString16(numberU16); dataParcel.WriteInt32(accountId); dataParcel.WriteInt32(videoState); dataParcel.WriteInt32(dialScene); dataParcel.WriteInt32(dialType); dataParcel.WriteInt32(callType); dataParcel.RewindRead(0); MessageParcel reply; return DelayedSingleton::GetInstance()->OnDialCall(dataParcel, reply); } void RemoveMissedIncomingCallNotification(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return; } MessageParcel dataMessageParcel; dataMessageParcel.WriteBuffer(data, size); dataMessageParcel.RewindRead(0); MessageParcel reply; DelayedSingleton::GetInstance()->OnRemoveMissedIncomingCallNotification( dataMessageParcel, reply); } int32_t SetCallWaiting(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return TELEPHONY_ERROR; } int32_t slotId = static_cast(size % SLOT_NUM); int32_t activate = static_cast(size % ACTIVE_NUM); MessageParcel dataParcel; dataParcel.WriteInt32(slotId); dataParcel.WriteBool(activate); dataParcel.RewindRead(0); MessageParcel reply; return DelayedSingleton::GetInstance()->OnSetCallWaiting(dataParcel, reply); } int32_t SetCallRestriction(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return TELEPHONY_ERROR; } CallRestrictionInfo info; int32_t slotId = static_cast(size % SLOT_NUM); std::string msg(reinterpret_cast(data), size); int32_t length = msg.length() > kMaxNumberLen ? kMaxNumberLen : msg.length(); memcpy_s(info.password, kMaxNumberLen, msg.c_str(), length); MessageParcel dataParcel; dataParcel.WriteInt32(slotId); dataParcel.WriteRawData((const void *)&info, sizeof(CallRestrictionInfo)); dataParcel.RewindRead(0); MessageParcel reply; return DelayedSingleton::GetInstance()->OnSetCallRestriction(dataParcel, reply); } int32_t JoinConference(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return TELEPHONY_ERROR; } int32_t callId = static_cast(size % CALL_ID_NUM); std::vector numberList { u"0000000000" }; MessageParcel dataParcel; dataParcel.WriteInt32(callId); dataParcel.WriteString16Vector(numberList); dataParcel.RewindRead(0); MessageParcel reply; return DelayedSingleton::GetInstance()->OnJoinConference(dataParcel, reply); } int32_t StartRtt(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return TELEPHONY_ERROR; } int32_t callId = static_cast(size % CALL_ID_NUM); std::string msg(reinterpret_cast(data), size); MessageParcel dataParcel; dataParcel.WriteInt32(callId); dataParcel.WriteString(msg); dataParcel.RewindRead(0); MessageParcel reply; return DelayedSingleton::GetInstance()->OnStartRtt(dataParcel, reply); } int32_t InputDialerSpecialCode(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return TELEPHONY_ERROR; } std::string specialCode(reinterpret_cast(data), size); MessageParcel dataParcel; dataParcel.WriteString(specialCode); dataParcel.RewindRead(0); MessageParcel reply; return DelayedSingleton::GetInstance()->OnInputDialerSpecialCode(dataParcel, reply); } int32_t CancelCallUpgrade(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return TELEPHONY_ERROR; } MessageParcel dataParcel; MessageParcel replyParcel; int32_t callId = static_cast(size % CALL_ID_NUM); dataParcel.WriteInt32(callId); dataParcel.RewindRead(0); return DelayedSingleton::GetInstance()->OnCancelCallUpgrade(dataParcel, replyParcel); } int32_t RequestCameraCapabilities(const uint8_t *data, size_t size) { if (!IsServiceInited()) { return TELEPHONY_ERROR; } MessageParcel dataParcel; MessageParcel replyParcel; int32_t callId = static_cast(size % CALL_ID_NUM); dataParcel.WriteInt32(callId); dataParcel.RewindRead(0); return DelayedSingleton::GetInstance()->OnRequestCameraCapabilities(dataParcel, replyParcel); } void DoSomethingInterestingWithMyAPI(const uint8_t *data, size_t size) { if (data == nullptr || size == 0) { return; } OnRegisterVoipCallManagerCallback(data, size); OnRemoteRequest(data, size); OnRegisterCallBack(data, size); HasCall(data, size); GetCallState(data, size); GetCallWaiting(data, size); IsRinging(data, size); IsInEmergencyCall(data, size); DialCall(data, size); RemoveMissedIncomingCallNotification(data, size); SetCallWaiting(data, size); SetCallRestriction(data, size); JoinConference(data, size); StartRtt(data, size); InputDialerSpecialCode(data, size); CancelCallUpgrade(data, size); RequestCameraCapabilities(data, size); } } // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { OHOS::AddCallTokenFuzzer token; /* Run your code on data */ OHOS::DoSomethingInterestingWithMyAPI(data, size); return 0; }