/* * Copyright (c) 2024 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 "softbusadapter_fuzzer.h" #include #include "securec.h" #include #include "distributed_mission_broadcast_listener.h" #include "softbus_adapter/softbus_adapter.h" namespace OHOS { namespace DistributedSchedule { void FuzzSendSoftbusEvent(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(uint32_t))) { return; } std::shared_ptr buffer = std::make_shared(size); if (memcpy_s(buffer->Data(), buffer->Capacity(), data, size) != ERR_OK) { return; } SoftbusAdapter::GetInstance().SendSoftbusEvent(buffer); SoftbusAdapter::GetInstance().StopSoftbusEvent(); } void FuzzOnBroadCastRecv(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(uint32_t))) { return; } std::string networkId(reinterpret_cast(data), size); uint8_t* newdata = const_cast(data); uint32_t dataLen = *(reinterpret_cast(data)); SoftbusAdapter::GetInstance().OnBroadCastRecv(networkId, newdata, dataLen); std::shared_ptr listener = std::make_shared(); SoftbusAdapter::GetInstance().RegisterSoftbusEventListener(listener); SoftbusAdapter::GetInstance().UnregisterSoftbusEventListener(listener); } } } /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { OHOS::DistributedSchedule::FuzzSendSoftbusEvent(data, size); OHOS::DistributedSchedule::FuzzOnBroadCastRecv(data, size); return 0; }