diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 971801c41a4f35a19454dbecc76caa27f4a2a3e0..f4754e413f2ce42b202317c042a1cb96404ae4c3 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -27,6 +27,7 @@ group("fuzztest") { "${services_path}/audiomanager/test/fuzztest/sinkservicestopdistributedhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkservicesubscribelocalhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkserviceunsubscribelocalhardware_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkstubonremoterequest_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer:fuzztest", @@ -46,6 +47,7 @@ group("fuzztest") { "sinkhandlersubscribelocalhardware_fuzzer:fuzztest", "sinkhandlerunsubscribelocalhardware_fuzzer:fuzztest", "sinkipccallbackonnotifyresourceinfo_fuzzer:fuzztest", + "sinkipccallbackonnotifyresourceinfoinner_fuzzer:fuzztest", "sinkipccallbackonremoterequest_fuzzer:fuzztest", "sinkonloadsystemabilityfail_fuzzer:fuzztest", "sinkonloadsystemabilitysuccess_fuzzer:fuzztest", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..e15a8c1b9cbeab324e2741be5052adb2693a9e6c --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/BUILD.gn @@ -0,0 +1,68 @@ +# 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkIpcCallbackOnNotifyResourceInfoInnerFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkipccallbackonnotifyresourceinfoinner" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sinkipccallbackonnotifyresourceinfoinner_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + ] + + deps = + [ "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkIpcCallbackOnNotifyResourceInfoInnerFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkIpcCallbackOnNotifyResourceInfoInnerFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/sinkipccallbackonnotifyresourceinfoinner_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/sinkipccallbackonnotifyresourceinfoinner_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..7d28ea0aa5a76c72bd29968f783d22f130b90976 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/sinkipccallbackonnotifyresourceinfoinner_fuzzer.cpp @@ -0,0 +1,71 @@ +/* + * 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 "sinkipccallbackonnotifyresourceinfoinner_fuzzer.h" + +#include +#include + +#include "daudio_sink_ipc_callback.h" +#include "daudio_sink_ipc_callback_stub.h" +#include "iremote_object.h" +#include "message_option.h" +#include "message_parcel.h" + +namespace OHOS { +namespace DistributedHardware { +const uint32_t DC_RESOURCE_VALUE = 2; +const uint32_t DC_RESOURCE_SIZE = 3; +const ResourceEventType resourceEventType[DC_RESOURCE_SIZE] { + ResourceEventType::EVENT_TYPE_QUERY_RESOURCE, + ResourceEventType::EVENT_TYPE_PULL_UP_PAGE, + ResourceEventType::EVENT_TYPE_CLOSE_PAGE +}; + +void SinkIpcCallbackOnNotifyResourceInfoInnerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + uint32_t code = 0; + int32_t resType = static_cast(resourceEventType[data[0] % DC_RESOURCE_SIZE]); + std::string subtype(reinterpret_cast(data), size); + std::string networkId(reinterpret_cast(data), size); + bool isSensitive = data[0] % DC_RESOURCE_VALUE; + bool isSameAccout = data[0] % DC_RESOURCE_VALUE; + pdata.WriteInt32(resType); + pdata.WriteString(subtype); + pdata.WriteString(networkId); + pdata.ReadBool(isSensitive); + pdata.ReadBool(isSameAccout); + std::shared_ptr callback = std::make_shared(); + callback->memberFuncMap_[code] = &DAudioSinkIpcCallbackStub::OnNotifyResourceInfoInner; + + callback->OnNotifyResourceInfoInner(pdata, reply, option); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkIpcCallbackOnNotifyResourceInfoInnerFuzzTest(data, size); + return 0; +} diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/sinkipccallbackonnotifyresourceinfoinner_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/sinkipccallbackonnotifyresourceinfoinner_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..d357cbf35592104150b0a90fd2d0f510fbd44b5a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfoinner_fuzzer/sinkipccallbackonnotifyresourceinfoinner_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef SINKIPCCALLBACKONNOTIFYRESOURCEINFOINNER_FUZZER_H +#define SINKIPCCALLBACKONNOTIFYRESOURCEINFOINNER_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkipccallbackonnotifyresourceinfoinner_fuzzer" + +#endif diff --git a/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1f2357f5b32534f5fdc0ecc25e19a760061b607c --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/BUILD.gn @@ -0,0 +1,69 @@ +# 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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkStubDaudioSinkStubFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkstubdaudiosinkstub_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sinkstubdaudiosinkstub_fuzzer.cpp" ] + + include_dirs = [ + "${fwk_utils_path}/include/log", + "${fwk_utils_path}/include", + "${fwk_common_path}/log/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${services_path}/audiomanager/servicesink/include", + ] + + deps = [ "${services_path}/audiomanager/servicesink:distributed_audio_sink" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkStubDaudioSinkStubFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkStubDaudioSinkStubFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * 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. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/sinkstubdaudiosinkstub_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/sinkstubdaudiosinkstub_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..23249699ce33c209afa1638c8481b1aacfcd35bc --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/sinkstubdaudiosinkstub_fuzzer.cpp @@ -0,0 +1,238 @@ +/* + * Copyright (c) 2023 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 "sinkstubdaudiosinkstub_fuzzer.h" + +#include +#include +#include + +#include "daudio_sink_stub.h" +#include "daudio_sink_service.h" + +#include "daudio_ipc_interface_code.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +const uint32_t RANGE = 8; +void SinkStubDaudioSinkStubFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + std::random_device rd; + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + std::string devId = "1"; + std::string dhId = "2"; + std::string reqId = "3"; + int32_t status = *(reinterpret_cast(data)); + std::string resultData(reinterpret_cast(data), size); + pdata.WriteString(devId); + pdata.WriteString(dhId); + pdata.WriteString(reqId); + pdata.WriteInt32(status); + pdata.WriteString(resultData); + dAudioSinkService->memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::INIT_SINK)] = + &DAudioSinkStub::InitSinkInner; + dAudioSinkService->memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::RELEASE_SINK)] = + &DAudioSinkStub::ReleaseSinkInner; + dAudioSinkService->memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::SUBSCRIBE_LOCAL_HARDWARE)] = + &DAudioSinkStub::SubscribeLocalHardwareInner; + dAudioSinkService->memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::UNSUBSCRIBE_LOCAL_HARDWARE)] = + &DAudioSinkStub::UnsubscribeLocalHardwareInner; + dAudioSinkService->memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::DAUDIO_NOTIFY)] = + &DAudioSinkStub::DAudioNotifyInner; + dAudioSinkService->memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::PAUSE_DISTRIBUTED_HARDWARE)] = + &DAudioSinkStub::PauseDistributedHardwareInner; + dAudioSinkService->memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::RESUME_DISTRIBUTED_HARDWARE)] = + &DAudioSinkStub::ResumeDistributedHardwareInner; + dAudioSinkService->memberFuncMap_[static_cast(IDAudioSinkInterfaceCode::STOP_DISTRIBUTED_HARDWARE)] = + &DAudioSinkStub::StopDistributedHardwareInner; + const uint32_t code = rd() % RANGE; + dAudioSinkService->OnRemoteRequest(code, pdata, reply, option); +} + +void SinkStubSubscribeLocalHardwareInnerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + std::random_device rd; + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + std::string devId = "1"; + std::string dhId = "2"; + std::string reqId = "3"; + int32_t status = *(reinterpret_cast(data)); + std::string resultData(reinterpret_cast(data), size); + pdata.WriteString(devId); + pdata.WriteString(dhId); + pdata.WriteString(reqId); + pdata.WriteInt32(status); + pdata.WriteString(resultData); + dAudioSinkService->SubscribeLocalHardwareInner(pdata, reply, option); +} + +void SinkStubUnsubscribeLocalHardwareInnerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + std::random_device rd; + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + std::string devId = "1"; + std::string dhId = "2"; + std::string reqId = "3"; + int32_t status = *(reinterpret_cast(data)); + std::string resultData(reinterpret_cast(data), size); + pdata.WriteString(devId); + pdata.WriteString(dhId); + pdata.WriteString(reqId); + pdata.WriteInt32(status); + pdata.WriteString(resultData); + dAudioSinkService->UnsubscribeLocalHardwareInner(pdata, reply, option); +} + +void SinkStubDAudioNotifyInnerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + std::random_device rd; + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + std::string devId = "1"; + std::string dhId = "2"; + std::string reqId = "3"; + int32_t status = *(reinterpret_cast(data)); + std::string resultData(reinterpret_cast(data), size); + pdata.WriteString(devId); + pdata.WriteString(dhId); + pdata.WriteString(reqId); + pdata.WriteInt32(status); + pdata.WriteString(resultData); + dAudioSinkService->DAudioNotifyInner(pdata, reply, option); +} + +void SinkStubPauseDistributedHardwareInnerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + std::random_device rd; + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + std::string devId = "1"; + std::string dhId = "2"; + std::string reqId = "3"; + int32_t status = *(reinterpret_cast(data)); + std::string resultData(reinterpret_cast(data), size); + pdata.WriteString(devId); + pdata.WriteString(dhId); + pdata.WriteString(reqId); + pdata.WriteInt32(status); + pdata.WriteString(resultData); + dAudioSinkService->PauseDistributedHardwareInner(pdata, reply, option); +} + +void SinkStubResumeDistributedHardwareInnerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + std::random_device rd; + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + std::string devId = "1"; + std::string dhId = "2"; + std::string reqId = "3"; + int32_t status = *(reinterpret_cast(data)); + std::string resultData(reinterpret_cast(data), size); + pdata.WriteString(devId); + pdata.WriteString(dhId); + pdata.WriteString(reqId); + pdata.WriteInt32(status); + pdata.WriteString(resultData); + dAudioSinkService->ResumeDistributedHardwareInner(pdata, reply, option); +} + +void SinkStubStopDistributedHardwareInnerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t saId = *(reinterpret_cast(data)); + bool runOnCreate = *(reinterpret_cast(data)); + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + std::random_device rd; + MessageParcel pdata; + MessageParcel reply; + MessageOption option; + std::string devId = "1"; + std::string dhId = "2"; + std::string reqId = "3"; + int32_t status = *(reinterpret_cast(data)); + std::string resultData(reinterpret_cast(data), size); + pdata.WriteString(devId); + pdata.WriteString(dhId); + pdata.WriteString(reqId); + pdata.WriteInt32(status); + pdata.WriteString(resultData); + dAudioSinkService->StopDistributedHardwareInner(pdata, reply, option); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkStubDaudioSinkStubFuzzTest(data, size); + OHOS::DistributedHardware::SinkStubSubscribeLocalHardwareInnerFuzzTest(data, size); + OHOS::DistributedHardware::SinkStubUnsubscribeLocalHardwareInnerFuzzTest(data, size); + OHOS::DistributedHardware::SinkStubDAudioNotifyInnerFuzzTest(data, size); + OHOS::DistributedHardware::SinkStubPauseDistributedHardwareInnerFuzzTest(data, size); + OHOS::DistributedHardware::SinkStubResumeDistributedHardwareInnerFuzzTest(data, size); + OHOS::DistributedHardware::SinkStubStopDistributedHardwareInnerFuzzTest(data, size); + return 0; +} diff --git a/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/sinkstubdaudiosinkstub_fuzzer.h b/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/sinkstubdaudiosinkstub_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..dd5af9bda83827be9c3d0b69c2b2cb6df13fa802 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkstubdaudiosinkstub_fuzzer/sinkstubdaudiosinkstub_fuzzer.h @@ -0,0 +1,21 @@ +/* + * 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. + */ + +#ifndef SINKSTUBDAUDIOSINKSTUB_FUZZER_H +#define SINKSTUBDAUDIOSINKSTUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkstubdaudiosinkstub_fuzzer" + +#endif \ No newline at end of file