From 13eb7eeb81f06425b14c5caa127eb5b42913d251 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 19 Jun 2025 20:34:40 +0800 Subject: [PATCH 01/10] add FUZZ Signed-off-by: BrainL --- av_transport/framework/filter/test/BUILD.gn | 5 +- .../framework/filter/test/fuzztest/BUILD.gn | 20 +++ .../fuzztest/filterfactory_fuzzer/BUILD.gn | 72 +++++++++ .../fuzztest/filterfactory_fuzzer/corpus/init | 16 ++ .../filterfactory_fuzzer.cpp | 42 +++++ .../filterfactory_fuzzer.h | 21 +++ .../fuzztest/filterfactory_fuzzer/project.xml | 25 +++ interfaces/inner_kits/test/fuzztest/BUILD.gn | 1 + .../distributedhardwarefwkkit_fuzzer.cpp | 92 +++++++++++ .../distributedhardwarefwkkit_fuzzer.h | 14 ++ .../BUILD.gn | 66 ++++++++ .../corpus/init | 14 ++ .../getdhdescriptorscallbackstub_fuzzer.cpp | 94 ++++++++++++ .../getdhdescriptorscallbackstub_fuzzer.h | 36 +++++ .../project.xml | 25 +++ .../BUILD.gn | 66 ++++++++ .../corpus/init | 14 ++ .../hardwarestatuslistenerstub_fuzzer.cpp | 92 +++++++++++ .../hardwarestatuslistenerstub_fuzzer.h | 42 +++++ .../project.xml | 25 +++ .../accessmanager_fuzzer.cpp | 85 ++++++++++- .../capabilityinfomanager_fuzzer/BUILD.gn | 7 +- .../capabilityinfomanager_fuzzer.cpp | 144 ++++++++++++++++++ .../capabilityinfomanager_fuzzer.h | 18 +++ .../componentdisable_fuzzer.cpp | 66 ++++++++ .../componentdisable_fuzzer.h | 27 +++- .../componentenable_fuzzer.cpp | 72 +++++++++ .../componentenable_fuzzer.h | 27 +++- .../dhcommtool_fuzzer/dhcommtool_fuzzer.cpp | 76 +++++++++ .../dhtransport_fuzzer/dhtransport_fuzzer.cpp | 73 +++++++++ 30 files changed, 1372 insertions(+), 5 deletions(-) create mode 100644 av_transport/framework/filter/test/fuzztest/BUILD.gn create mode 100644 av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/BUILD.gn create mode 100644 av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/corpus/init create mode 100644 av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.cpp create mode 100644 av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.h create mode 100644 av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/project.xml create mode 100644 interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.cpp create mode 100644 interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.h create mode 100644 interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/project.xml create mode 100644 interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp create mode 100644 interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.h create mode 100644 interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/project.xml diff --git a/av_transport/framework/filter/test/BUILD.gn b/av_transport/framework/filter/test/BUILD.gn index 478d68bb..0c9c1829 100644 --- a/av_transport/framework/filter/test/BUILD.gn +++ b/av_transport/framework/filter/test/BUILD.gn @@ -14,5 +14,8 @@ group("framework_filter_test") { testonly = true - deps = [ "unittest:framework_filter_unittest" ] + deps = [ + "unittest:framework_filter_unittest", + "fuzztest:fuzztest", + ] } diff --git a/av_transport/framework/filter/test/fuzztest/BUILD.gn b/av_transport/framework/filter/test/fuzztest/BUILD.gn new file mode 100644 index 00000000..cc8f2e25 --- /dev/null +++ b/av_transport/framework/filter/test/fuzztest/BUILD.gn @@ -0,0 +1,20 @@ +# Copyright (c) 2025 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. + +group("fuzztest") { + testonly = true + + deps = [ + "filterfactory_fuzzer:fuzztest" + ] +} diff --git a/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/BUILD.gn b/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/BUILD.gn new file mode 100644 index 00000000..2b8157d2 --- /dev/null +++ b/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2025 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("../../../../../distributed_av_transport.gni") + +##############################fuzztest########################################## +ohos_fuzztest("FilterFactoryFuzzTest") { + module_out_path = "distributed_hardware_fwk/av_transport/filter" + fuzz_config_file = + "${filter_path}/test/fuzztest/filterfactory_fuzzer" + + include_dirs = [ + "${common_path}/include", + "${filter_path}/include", + "${filter_path}/test/fuzztest", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + ] + + sources = [ "filterfactory_fuzzer.cpp" ] + + deps = [ + "${distributed_av_transport_path}/framework:distributed_av_pipeline_fwk" + ] + if (histreamer_compile_part) { + external_deps = [ + "media_foundation:histreamer_base", + "media_foundation:histreamer_codec_filters", + "media_foundation:histreamer_ffmpeg_convert", + "media_foundation:histreamer_plugin_base", + ] + } + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"FilterFactoryFuzzTest\"", + "LOG_DOMAIN=0xD004101", + ] + + external_deps += [ + "cJSON:cjson", + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":FilterFactoryFuzzTest" ] +} +############################################################################### diff --git a/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/corpus/init b/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.cpp b/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.cpp new file mode 100644 index 00000000..68795319 --- /dev/null +++ b/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.cpp @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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 +#include "filter_factory.h" +#include "filterfactory_fuzzer.h" + +namespace OHOS { +namespace DistributedHardware { +namespace Pipeline { +void FilterFactoryFuzzerTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + std::string filterName(reinterpret_cast(data), size - 1); + FilterType type = static_cast(data[size - 1]); + auto filter = FilterFactory::Instance().CreateFilterPriv(filterName, type); +} +} // namespace Pipeline +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::Pipeline::FilterFactoryFuzzerTest(data, size); + return 0; +} \ No newline at end of file diff --git a/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.h b/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.h new file mode 100644 index 00000000..2131ce39 --- /dev/null +++ b/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 TEST_FILTERFACTORY_FUZZER_H +#define TEST_FILTERFACTORY_FUZZER_H + +#define FUZZ_PROJECT_NAME "filterfactory_fuzzer.cpp" + +#endif \ No newline at end of file diff --git a/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/project.xml b/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/project.xml new file mode 100644 index 00000000..66e1dcac --- /dev/null +++ b/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/test/fuzztest/BUILD.gn b/interfaces/inner_kits/test/fuzztest/BUILD.gn index dca382b0..2e759f50 100644 --- a/interfaces/inner_kits/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/test/fuzztest/BUILD.gn @@ -17,5 +17,6 @@ group("fuzztest") { deps = [ "distributedhardwarefwkkit_fuzzer:fuzztest", "distributedhardwarefwkstub_fuzzer:fuzztest", + "getdhdescriptorscallbackstub_fuzzer:fuzztest", ] } diff --git a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.cpp b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.cpp index ec0f7234..b9ed0225 100644 --- a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.cpp +++ b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.cpp @@ -78,6 +78,24 @@ void TestGetDistributedHardwareCallback::OnError(const std::string &networkId, i (void)error; } +int32_t TestAVTransControlCenterCallback::SetParameter(AVTransTag tag, const std::string &value) +{ + (void)tag; + (void)value; + return DH_FWK_SUCCESS; +} + +int32_t TestAVTransControlCenterCallback::SetSharedMemory(const AVTransSharedMemory &memory) +{ + (void)memory; + return DH_FWK_SUCCESS; +} + +int32_t TestAVTransControlCenterCallback::Notify(const AVTransEvent &event) +{ + (void)event; + return DH_FWK_SUCCESS; +} void RegisterPublisherListenerFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size < sizeof(uint32_t))) { @@ -328,6 +346,74 @@ void UnLoadDistributedHDFFuzzTest(const uint8_t *data, size_t size) DistributedHardwareFwkKit dhfwkKit; dhfwkKit.UnLoadDistributedHDF(dhType); } + +void OnDHFWKOnLineFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + DistributedHardwareFwkKit dhfwkKit; + bool isOnLine = *(reinterpret_cast(data)); + dhfwkKit.OnDHFWKOnLine(isOnLine); +} + +void QueryLocalSysSpecFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + DistributedHardwareFwkKit dhfwkKit; + enum QueryLocalSysSpecType specType = + static_cast(*(reinterpret_cast(data))); + dhfwkKit.QueryLocalSysSpec(specType); +} + +void RegisterDHStatusListenerOneParamFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + DistributedHardwareFwkKit dhfwkKit; + sptr listener(new TestHDSinkStatusListener()); + dhfwkKit.RegisterDHStatusListener(listener); +} + +void UnregisterDHStatusListenerOneParamFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + DistributedHardwareFwkKit dhfwkKit; + sptr listener(new TestHDSinkStatusListener()); + dhfwkKit.UnregisterDHStatusListener(listener); +} + +void IsQueryLocalSysSpecTypeValidFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + DistributedHardwareFwkKit dhfwkKit; + QueryLocalSysSpecType specType = static_cast(*(reinterpret_cast(data))); + dhfwkKit.IsQueryLocalSysSpecTypeValid(specType); +} + +void RegisterCtlCenterCallback(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + DistributedHardwareFwkKit dhfwkKit; + int32_t engineId = *(reinterpret_cast(data)); + sptr listener(new TestAVTransControlCenterCallback()); + dhfwkKit.RegisterCtlCenterCallback(engineId, listener); +} } // namespace DistributedHardware } // namespace OHOS @@ -354,5 +440,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) OHOS::DistributedHardware::DisableSinkFuzzTest(data, size); OHOS::DistributedHardware::LoadDistributedHDFFuzzTest(data, size); OHOS::DistributedHardware::UnLoadDistributedHDFFuzzTest(data, size); + OHOS::DistributedHardware::OnDHFWKOnLineFuzzTest(data, size); + OHOS::DistributedHardware::QueryLocalSysSpecFuzzTest(data, size); + OHOS::DistributedHardware::RegisterDHStatusListenerOneParamFuzzTest(data, size); + OHOS::DistributedHardware::UnregisterDHStatusListenerOneParamFuzzTest(data, size); + OHOS::DistributedHardware::IsQueryLocalSysSpecTypeValidFuzzTest(data, size); + OHOS::DistributedHardware::RegisterCtlCenterCallback(data, size); return 0; } \ No newline at end of file diff --git a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.h b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.h index fefe64db..ebdaf545 100644 --- a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.h +++ b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.h @@ -21,6 +21,7 @@ #include #include "get_dh_descriptors_callback_stub.h" #include "hardware_status_listener_stub.h" +#include "iav_trans_control_center_callback.h" #include "publisher_listener_stub.h" namespace OHOS { @@ -59,6 +60,19 @@ protected: EnableStep enableStep) override; void OnError(const std::string &networkId, int32_t error) override; }; +class TestAVTransControlCenterCallback : public IAVTransControlCenterCallback { +public: + TestAVTransControlCenterCallback() = default; + virtual ~TestAVTransControlCenterCallback() = default; +protected: + int32_t SetParameter(AVTransTag tag, const std::string &value) override; + int32_t SetSharedMemory(const AVTransSharedMemory &memory) override; + int32_t Notify(const AVTransEvent &event) override; + sptr AsObject() override + { + return nullptr; + } +}; } // namespace DistributedHardware } // namespace OHOS #endif \ No newline at end of file diff --git a/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/BUILD.gn b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/BUILD.gn new file mode 100644 index 00000000..201257c0 --- /dev/null +++ b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2025 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("../../../../../distributedhardwarefwk.gni") + +##############################fuzztest########################################## +ohos_fuzztest("GetDhDescriptorsCallbackStubFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${innerkits_path}/test/fuzztest/getdhdescriptorscallbackstub_fuzzer" + + include_dirs = [ + "${av_trans_path}/common/include", + "include", + "${utils_path}/include", + "${common_path}/utils/include", + "${common_path}/log/include", + "${services_path}/distributedhardwarefwkservice/include", + "${services_path}/distributedhardwarefwkservice/include/accessmanager", + "${innerkits_path}/include", + "${innerkits_path}/include/ipc", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + ] + sources = [ "getdhdescriptorscallbackstub_fuzzer.cpp" ] + + deps = [ "${innerkits_path}:libdhfwk_sdk" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"GetDhDescriptorsCallbackStubFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":GetDhDescriptorsCallbackStubFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/corpus/init b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/corpus/init new file mode 100644 index 00000000..65af8ee8 --- /dev/null +++ b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2025 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/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.cpp b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.cpp new file mode 100644 index 00000000..a613f010 --- /dev/null +++ b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.cpp @@ -0,0 +1,94 @@ +/* + * Copyright (c) 2025 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 "getdhdescriptorscallbackstub_fuzzer.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "constants.h" +#include "dhardware_descriptor.h" +#include "distributed_hardware_errno.h" +#include "distributed_hardware_log.h" +#include "get_dh_descriptors_callback_stub.h" +#include "publisher_listener_stub.h" + +namespace OHOS { +namespace DistributedHardware { + +void FuzzGetDhDescriptorsCallbackStub::OnSuccess( + const std::string &networkId, const std::vector &descriptors, EnableStep enableStep) +{ + (void)networkId; + (void)descriptors; + (void)enableStep; +} + +void FuzzGetDhDescriptorsCallbackStub::OnError(const std::string &networkId, int32_t error) +{ + (void)networkId; + (void)error; +} + +void OnRemoteRequestFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t))) { + return; + } + MessageParcel parcel; + parcel.WriteInterfaceToken(FuzzGetDhDescriptorsCallbackStub().GetDescriptor()); + uint32_t dhType = *(reinterpret_cast(data)); + parcel.WriteUint32(dhType); + std::string id(reinterpret_cast(data + 4), size - 4); + parcel.WriteString(id); + MessageParcel reply; + MessageOption option; + + uint32_t code = 0; + if (size >= sizeof(uint32_t)) { + code = *(reinterpret_cast(data)); + } + + FuzzGetDhDescriptorsCallbackStub stub; + stub.OnRemoteRequest(code, parcel, reply, option); +} +void ReadDescriptorsFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t))) { + return; + } + MessageParcel parcel; + parcel.WriteBuffer(data, size); + + FuzzGetDhDescriptorsCallbackStub stub; + std::vector descriptors; + stub.ReadDescriptors(parcel, descriptors); +} +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::OnRemoteRequestFuzzTest(data, size); + OHOS::DistributedHardware::ReadDescriptorsFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.h b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.h new file mode 100644 index 00000000..466f50a6 --- /dev/null +++ b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.h @@ -0,0 +1,36 @@ +/* + * Copyright (c) 2025 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 TEST_GET_DH_DESCRIPTORS_CALLBACK_STUB_FUZZER_H +#define TEST_GET_DH_DESCRIPTORS_CALLBACK_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "getdhdescriptorscallbackstub_fuzzer.cpp" + +#include +#include "get_dh_descriptors_callback_stub.h" +#include "dhardware_descriptor.h" +#include "constants.h" + +namespace OHOS { +namespace DistributedHardware { + +class FuzzGetDhDescriptorsCallbackStub : public GetDhDescriptorsCallbackStub { +public: + void OnSuccess(const std::string &, const std::vector &, EnableStep) override; + void OnError(const std::string &, int32_t) override; +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/project.xml b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/project.xml new file mode 100644 index 00000000..66e1dcac --- /dev/null +++ b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/BUILD.gn b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/BUILD.gn new file mode 100644 index 00000000..2466f31b --- /dev/null +++ b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/BUILD.gn @@ -0,0 +1,66 @@ +# Copyright (c) 2025 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("../../../../../distributedhardwarefwk.gni") + +##############################fuzztest########################################## +ohos_fuzztest("HardwareStatusListenerStubFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${innerkits_path}/test/fuzztest/hardwarestatuslistenerstub_fuzzer" + + include_dirs = [ + "${av_trans_path}/common/include", + "include", + "${utils_path}/include", + "${common_path}/utils/include", + "${common_path}/log/include", + "${services_path}/distributedhardwarefwkservice/include", + "${services_path}/distributedhardwarefwkservice/include/accessmanager", + "${innerkits_path}/include", + "${innerkits_path}/include/ipc", + ] + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + ] + sources = [ "hardwarestatuslistenerstub_fuzzer.cpp" ] + + deps = [ "${innerkits_path}:libdhfwk_sdk" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"HardwareStatusListenerStubFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":HardwareStatusListenerStubFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/corpus/init b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/corpus/init new file mode 100644 index 00000000..65af8ee8 --- /dev/null +++ b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# Copyright (c) 2025 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/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp new file mode 100644 index 00000000..70757c1c --- /dev/null +++ b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2025 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 "hardwarestatuslistenerstub_fuzzer.h" + +#include +#include +#include +#include +#include +#include +#include + +#include "constants.h" +#include "dhardware_descriptor.h" +#include "distributed_hardware_errno.h" +#include "distributed_hardware_log.h" +#include "hardware_status_listener_stub.h" +#include "publisher_listener_stub.h" + +namespace OHOS { +namespace DistributedHardware { +void HDSinkStatusOnRemoteRequestFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t))) { + return; + } + MessageParcel parcel; + parcel.WriteInterfaceToken(FuzzHDSinkStatusListenerStub().GetDescriptor()); + uint32_t dhType = *(reinterpret_cast(data)); + parcel.WriteUint32(dhType); + std::string id(reinterpret_cast(data + 4), size - 4); + parcel.WriteString(id); + MessageParcel reply; + MessageOption option; + + uint32_t code = 0; + if (size >= sizeof(uint32_t)) { + code = *(reinterpret_cast(data)); + } + + FuzzHDSinkStatusListenerStub stub; + + stub.OnRemoteRequest(code, parcel, reply, option); + +} +void HDSourceStatusOnRemoteRequestFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t))) { + return; + } + + MessageParcel parcel; + parcel.WriteInterfaceToken(FuzzHDSinkStatusListenerStub().GetDescriptor()); + uint32_t dhType = *(reinterpret_cast(data)); + parcel.WriteUint32(dhType); + std::string id(reinterpret_cast(data + 4), size - 4); + parcel.WriteString(id); + MessageParcel reply; + MessageOption option; + + uint32_t code = 0; + if (size >= sizeof(uint32_t)) { + code = *(reinterpret_cast(data)); + } + FuzzHDSourceStatusListenerStub stub; + + stub.OnRemoteRequest(code, parcel, reply, option); +} +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::HDSinkStatusOnRemoteRequestFuzzTest(data, size); + OHOS::DistributedHardware::HDSourceStatusOnRemoteRequestFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.h b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.h new file mode 100644 index 00000000..3874bace --- /dev/null +++ b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.h @@ -0,0 +1,42 @@ +/* + * Copyright (c) 2025 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 TEST_HARDWARE_STATUS_LISTENER_STUB_FUZZER_H +#define TEST_HARDWARE_STATUS_LISTENER_STUB_FUZZER_H + +#define FUZZ_PROJECT_NAME "hardwarestatuslistenerstub_fuzz.cpp" + +#include +#include "hardware_status_listener_stub.h" +#include "dhardware_descriptor.h" +#include "constants.h" + +namespace OHOS { +namespace DistributedHardware { + +class FuzzHDSinkStatusListenerStub : public HDSinkStatusListenerStub { +public: + void OnEnable(const DHDescriptor&) override {} + void OnDisable(const DHDescriptor&) override {} +}; + +class FuzzHDSourceStatusListenerStub : public HDSourceStatusListenerStub { +public: + void OnEnable(const std::string&, const DHDescriptor&) override {} + void OnDisable(const std::string&, const DHDescriptor&) override {} +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/project.xml b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/project.xml new file mode 100644 index 00000000..66e1dcac --- /dev/null +++ b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/distributedhardwarefwkservice/test/fuzztest/accessmanager_fuzzer/accessmanager_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/accessmanager_fuzzer/accessmanager_fuzzer.cpp index ab8eb762..4d4d8f92 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/accessmanager_fuzzer/accessmanager_fuzzer.cpp +++ b/services/distributedhardwarefwkservice/test/fuzztest/accessmanager_fuzzer/accessmanager_fuzzer.cpp @@ -52,7 +52,7 @@ void OnDeviceReadyFuzzTest(const uint8_t* data, size_t size) usleep(SLEEP_TIME_US); } -void OnDeviceOnlineFuzzTest(const uint8_t* data, size_t size) +void OnDeviceOfflineFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size > DM_MAX_DEVICE_ID_LEN)) { return; @@ -83,6 +83,84 @@ void OnDeviceChangedFuzzTest(const uint8_t* data, size_t size) AccessManager::GetInstance()->OnDeviceChanged(deviceInfo); usleep(SLEEP_TIME_US); } + +void UnInitFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size > DM_MAX_DEVICE_ID_LEN)) { + return; + } + + AccessManager::GetInstance()->UnInit(); + usleep(SLEEP_TIME_US); +} + +void UnInitDeviceManagerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size > DM_MAX_DEVICE_ID_LEN)) { + return; + } + + AccessManager::GetInstance()->UnInitDeviceManager(); + usleep(SLEEP_TIME_US); +} + +void UnRegisterDevStateCallbackFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size > DM_MAX_DEVICE_ID_LEN)) { + return; + } + + AccessManager::GetInstance()->UnRegisterDevStateCallback(); + usleep(SLEEP_TIME_US); +} + +void OnRemoteDiedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size > DM_MAX_DEVICE_ID_LEN)) { + return; + } + + AccessManager::GetInstance()->OnRemoteDied(); + usleep(SLEEP_TIME_US); +} + +void CheckTrustedDeviceOnlineFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size > DM_MAX_DEVICE_ID_LEN)) { + return; + } + + AccessManager::GetInstance()->CheckTrustedDeviceOnline(); + usleep(SLEEP_TIME_US); +} + +void DumpFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size > DM_MAX_DEVICE_ID_LEN)) { + return; + } + + std::vector argsStr = {reinterpret_cast(data)}; + std::string result = {reinterpret_cast(data)}; + AccessManager::GetInstance()->Dump(argsStr, result); + usleep(SLEEP_TIME_US); +} + +void OnDeviceOnlineFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size > DM_MAX_DEVICE_ID_LEN)) { + return; + } + + AccessManager::GetInstance()->Init(); + DmDeviceInfo deviceInfo; + int32_t ret = memcpy_s(deviceInfo.networkId, DM_MAX_DEVICE_ID_LEN, (reinterpret_cast(data)), size); + if (ret != EOK) { + return; + } + AccessManager::GetInstance()->OnDeviceOnline(deviceInfo); + usleep(SLEEP_TIME_US); +} } } @@ -93,6 +171,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::DistributedHardware::OnDeviceReadyFuzzTest(data, size); OHOS::DistributedHardware::OnDeviceOnlineFuzzTest(data, size); OHOS::DistributedHardware::OnDeviceChangedFuzzTest(data, size); + OHOS::DistributedHardware::UnInitFuzzTest(data, size); + OHOS::DistributedHardware::OnRemoteDiedFuzzTest(data, size); + OHOS::DistributedHardware::CheckTrustedDeviceOnlineFuzzTest(data, size); + OHOS::DistributedHardware::DumpFuzzTest(data, size); + OHOS::DistributedHardware::OnDeviceOfflineFuzzTest(data, size); return 0; } diff --git a/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/BUILD.gn b/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/BUILD.gn index e145d2a2..79062233 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/BUILD.gn @@ -25,6 +25,7 @@ ohos_fuzztest("CapabilityInfoManagerFuzzTest") { "${utils_path}/include", "${common_path}/log/include", "${common_path}/utils/include", + "${innerkits_path}/include/ipc", "${services_path}/distributedhardwarefwkservice/include/resourcemanager", "${services_path}/distributedhardwarefwkservice/include/utils", ] @@ -33,8 +34,12 @@ ohos_fuzztest("CapabilityInfoManagerFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", + "-Dprivate=public", + ] + sources = [ + "capabilityinfomanager_fuzzer.cpp", + "${innerkits_path}/src/ipc/get_dh_descriptors_callback_stub.cpp", ] - sources = [ "capabilityinfomanager_fuzzer.cpp" ] deps = [ "${services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", diff --git a/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/capabilityinfomanager_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/capabilityinfomanager_fuzzer.cpp index c3103c8c..4469aea1 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/capabilityinfomanager_fuzzer.cpp +++ b/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/capabilityinfomanager_fuzzer.cpp @@ -27,6 +27,21 @@ namespace OHOS { namespace DistributedHardware { namespace { constexpr uint16_t TEST_DEV_TYPE_PAD = 0x11; + constexpr int32_t EVEN_CHECK = 2; +} + +void TestGetDistributedHardwareCallback::OnSuccess(const std::string &networkId, + const std::vector &descriptors, EnableStep enableStep) +{ + (void)networkId; + (void)descriptors; + (void)enableStep; +} + +void TestGetDistributedHardwareCallback::OnError(const std::string &networkId, int32_t error) +{ + (void)networkId; + (void)error; } void CapabilityInfoManagerFuzzTest(const uint8_t* data, size_t size) @@ -272,6 +287,126 @@ void CapabilityInfoManagerOnChangeDeleteFuzzTest(const uint8_t* data, size_t siz cJSON_free(cjson); cJSON_Delete(deleteJson); } + +void HasCapabilityFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + std::string dhId(reinterpret_cast(data), size); + std::string deviceId(reinterpret_cast(data), size); + + CapabilityInfoManager::GetInstance()->HasCapability(deviceId, dhId); +} + +void DumpCapabilityInfosFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + std::vector capInfos; + + CapabilityInfoManager::GetInstance()->DumpCapabilityInfos(capInfos); +} + +void CapabilityInfoManagerEventHandlerCtorFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + auto runner = AppExecFwk::EventRunner::Create(true); + std::shared_ptr mgrPtr; + if (data[0] % EVEN_CHECK == 0) { + mgrPtr = nullptr; + } else { + mgrPtr = std::make_shared(); + } + + CapabilityInfoManager::CapabilityInfoManagerEventHandler handler(runner, mgrPtr); + CapabilityInfoManager::GetInstance()->Init(); + CapabilityInfoManager::CapabilityInfoManagerEventHandler handler2(runner, mgrPtr); + CapabilityInfoManager::GetInstance()->UnInit(); +} + +void GetEventHandlerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + CapabilityInfoManager::GetInstance()->GetEventHandler(); +} + +void OnChangeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + std::string uuId(reinterpret_cast(data), size); + std::string deviceId = Sha256(uuId); + DistributedKv::Entry insert; + DistributedKv::Entry update; + DistributedKv::Entry del; + std::vector inserts; + std::vector updates; + std::vector deleteds; + inserts.push_back(insert); + updates.push_back(update); + deleteds.push_back(del); + + DistributedKv::ChangeNotification changeIn(std::move(inserts), std::move(updates), std::move(deleteds), + deviceId, true); + CapabilityInfoManager::GetInstance()->OnChange(changeIn); +} + +void GetDataByDHTypeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + DHType dhType = static_cast(data[0]); + std::map> capabilityMap; + CapabilityInfoManager::GetInstance()->GetDataByDHType(dhType, capabilityMap); +} + +void AsyncGetDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + std::string networkId(reinterpret_cast(data), size); + EnableStep enableStep = static_cast(data[0] % 4); + sptr callback(new TestGetDistributedHardwareCallback()); + CapabilityInfoManager::GetInstance()->AsyncGetDistributedHardware(networkId, enableStep, callback); +} + +void DoAsyncGetDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + std::string networkId(reinterpret_cast(data), size); + EnableStep enableStep = static_cast(data[0] % 4); + sptr callback(new TestGetDistributedHardwareCallback()); + CapabilityInfoManager::GetInstance()->DoAsyncGetDistributedHardware(networkId, enableStep, callback); +} + +void GetEntriesByKeysFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + std::vector keys = {std::string(reinterpret_cast(data), size)}; + CapabilityInfoManager::GetInstance()->GetEntriesByKeys(keys); +} } } @@ -289,6 +424,15 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::DistributedHardware::CapabilityInfoManagerOnChangeInsertFuzzTest(data, size); OHOS::DistributedHardware::CapabilityInfoManagerOnChangeUpdateFuzzTest(data, size); OHOS::DistributedHardware::CapabilityInfoManagerOnChangeDeleteFuzzTest(data, size); + OHOS::DistributedHardware::HasCapabilityFuzzTest(data, size); + OHOS::DistributedHardware::DumpCapabilityInfosFuzzTest(data, size); + OHOS::DistributedHardware::CapabilityInfoManagerEventHandlerCtorFuzzTest(data, size); + OHOS::DistributedHardware::GetEventHandlerFuzzTest(data, size); + OHOS::DistributedHardware::OnChangeFuzzTest(data, size); + OHOS::DistributedHardware::GetDataByDHTypeFuzzTest(data, size); + OHOS::DistributedHardware::AsyncGetDistributedHardwareFuzzTest(data, size); + OHOS::DistributedHardware::DoAsyncGetDistributedHardwareFuzzTest(data, size); + OHOS::DistributedHardware::GetEntriesByKeysFuzzTest(data, size); return 0; } diff --git a/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/capabilityinfomanager_fuzzer.h b/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/capabilityinfomanager_fuzzer.h index 7765bca2..07943503 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/capabilityinfomanager_fuzzer.h +++ b/services/distributedhardwarefwkservice/test/fuzztest/capabilityinfomanager_fuzzer/capabilityinfomanager_fuzzer.h @@ -18,5 +18,23 @@ #define FUZZ_PROJECT_NAME "capabilityinfomanager_fuzzer" +#include +#include "get_dh_descriptors_callback_stub.h" + +namespace OHOS { +namespace DistributedHardware { + +class TestGetDistributedHardwareCallback : public GetDhDescriptorsCallbackStub { +public: + TestGetDistributedHardwareCallback() = default; + virtual ~TestGetDistributedHardwareCallback() = default; +protected: + void OnSuccess(const std::string &networkId, const std::vector &descriptors, + EnableStep enableStep) override; + void OnError(const std::string &networkId, int32_t error) override; +}; +} // namespace DistributedHardware +} // namespace OHOS + #endif diff --git a/services/distributedhardwarefwkservice/test/fuzztest/componentdisable_fuzzer/componentdisable_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/componentdisable_fuzzer/componentdisable_fuzzer.cpp index 46d2158d..9ccdf7c3 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/componentdisable_fuzzer/componentdisable_fuzzer.cpp +++ b/services/distributedhardwarefwkservice/test/fuzztest/componentdisable_fuzzer/componentdisable_fuzzer.cpp @@ -21,6 +21,57 @@ namespace OHOS { namespace DistributedHardware { +int32_t FuzzDistributedHardwareSource::InitSource(const std::string& networkId) +{ + (void)networkId; + return DH_FWK_SUCCESS; +} + +int32_t FuzzDistributedHardwareSource::ReleaseSource() +{ + return DH_FWK_SUCCESS; +} + +int32_t FuzzDistributedHardwareSource::RegisterDistributedHardware( + const std::string& networkId, const std::string& dhId, const EnableParam& param, + std::shared_ptr callback) +{ + (void)networkId; + (void)dhId; + (void)param; + (void)callback; + return DH_FWK_SUCCESS; +} + +int32_t FuzzDistributedHardwareSource::UnregisterDistributedHardware( + const std::string& networkId, const std::string& dhId, std::shared_ptr callback) +{ + (void)networkId; + (void)dhId; + (void)callback; + return DH_FWK_SUCCESS; +} + +int32_t FuzzDistributedHardwareSource::ConfigDistributedHardware( + const std::string& networkId, const std::string& dhId, const std::string& key, const std::string& value) +{ + (void)networkId; + (void)dhId; + (void)key; + (void)value; + return DH_FWK_SUCCESS; +} + +void FuzzDistributedHardwareSource::RegisterDistributedHardwareStateListener( + std::shared_ptr listener) +{ + (void)listener; +} + +void FuzzDistributedHardwareSource::RegisterDataSyncTriggerListener(std::shared_ptr listener) +{ + (void)listener; +} void ComponentDisableFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size == 0)) { @@ -34,6 +85,20 @@ void ComponentDisableFuzzTest(const uint8_t* data, size_t size) std::string disableData(reinterpret_cast(data), size); compDisable->OnUnregisterResult(uuid, dhId, status, disableData); } + +void DisableFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + auto compDisable = std::make_shared(); + std::string networkId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + auto handler = std::make_shared(); + std::string disableData(reinterpret_cast(data), size); + compDisable->Disable(networkId, dhId, handler.get()); +} } } @@ -42,6 +107,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::ComponentDisableFuzzTest(data, size); + OHOS::DistributedHardware::DisableFuzzTest(data, size); return 0; } diff --git a/services/distributedhardwarefwkservice/test/fuzztest/componentdisable_fuzzer/componentdisable_fuzzer.h b/services/distributedhardwarefwkservice/test/fuzztest/componentdisable_fuzzer/componentdisable_fuzzer.h index 2e3cc0c2..0f664e2b 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/componentdisable_fuzzer/componentdisable_fuzzer.h +++ b/services/distributedhardwarefwkservice/test/fuzztest/componentdisable_fuzzer/componentdisable_fuzzer.h @@ -18,5 +18,30 @@ #define FUZZ_PROJECT_NAME "componentdisable_fuzzer" -#endif +#include +#include "idistributed_hardware_source.h" + +namespace OHOS { +namespace DistributedHardware { +class FuzzDistributedHardwareSource : public IDistributedHardwareSource { +public: + FuzzDistributedHardwareSource() = default; + virtual ~FuzzDistributedHardwareSource() = default; + + int32_t InitSource(const std::string&) override; + int32_t ReleaseSource() override; + int32_t RegisterDistributedHardware(const std::string&, const std::string&, + const EnableParam&, std::shared_ptr) override; + int32_t UnregisterDistributedHardware(const std::string&, const std::string&, + std::shared_ptr callback) override; + int32_t ConfigDistributedHardware(const std::string&, const std::string&, const std::string&, + const std::string&) override; + void RegisterDistributedHardwareStateListener(std::shared_ptr) override; + void UnregisterDistributedHardwareStateListener() override{} + void RegisterDataSyncTriggerListener(std::shared_ptr) override; + void UnregisterDataSyncTriggerListener() override{} +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/services/distributedhardwarefwkservice/test/fuzztest/componentenable_fuzzer/componentenable_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/componentenable_fuzzer/componentenable_fuzzer.cpp index 8943f0ba..ec9cb849 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/componentenable_fuzzer/componentenable_fuzzer.cpp +++ b/services/distributedhardwarefwkservice/test/fuzztest/componentenable_fuzzer/componentenable_fuzzer.cpp @@ -21,6 +21,58 @@ namespace OHOS { namespace DistributedHardware { +int32_t FuzzDistributedHardwareSource::InitSource(const std::string& networkId) +{ + (void)networkId; + return DH_FWK_SUCCESS; +} + +int32_t FuzzDistributedHardwareSource::ReleaseSource() +{ + return DH_FWK_SUCCESS; +} + +int32_t FuzzDistributedHardwareSource::RegisterDistributedHardware( + const std::string& networkId, const std::string& dhId, const EnableParam& param, + std::shared_ptr callback) +{ + (void)networkId; + (void)dhId; + (void)param; + (void)callback; + return DH_FWK_SUCCESS; +} + +int32_t FuzzDistributedHardwareSource::UnregisterDistributedHardware( + const std::string& networkId, const std::string& dhId, std::shared_ptr callback) +{ + (void)networkId; + (void)dhId; + (void)callback; + return DH_FWK_SUCCESS; +} + +int32_t FuzzDistributedHardwareSource::ConfigDistributedHardware( + const std::string& networkId, const std::string& dhId, const std::string& key, const std::string& value) +{ + (void)networkId; + (void)dhId; + (void)key; + (void)value; + return DH_FWK_SUCCESS; +} + +void FuzzDistributedHardwareSource::RegisterDistributedHardwareStateListener( + std::shared_ptr listener) +{ + (void)listener; +} + +void FuzzDistributedHardwareSource::RegisterDataSyncTriggerListener(std::shared_ptr listener) +{ + (void)listener; +} + void ComponentEnableFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size == 0)) { @@ -34,6 +86,25 @@ void ComponentEnableFuzzTest(const uint8_t* data, size_t size) std::string enableData(reinterpret_cast(data), size); compEnable->OnRegisterResult(uuid, dhId, status, enableData); } + +void EnableFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + auto compEnable = std::make_shared(); + std::string networkId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + EnableParam param; + param.sourceVersion = std::string(reinterpret_cast(data), size); + param.sourceAttrs = std::string(reinterpret_cast(data), size); + param.sinkVersion = std::string(reinterpret_cast(data), size); + param.sinkAttrs = std::string(reinterpret_cast(data), size); + param.subtype = std::string(reinterpret_cast(data), size); + auto handler = std::make_shared(); + compEnable->Enable(networkId, dhId, param, handler.get()); +} } } @@ -42,6 +113,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::ComponentEnableFuzzTest(data, size); + OHOS::DistributedHardware::EnableFuzzTest(data, size); return 0; } diff --git a/services/distributedhardwarefwkservice/test/fuzztest/componentenable_fuzzer/componentenable_fuzzer.h b/services/distributedhardwarefwkservice/test/fuzztest/componentenable_fuzzer/componentenable_fuzzer.h index 9fa3cb91..3ec7cc3c 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/componentenable_fuzzer/componentenable_fuzzer.h +++ b/services/distributedhardwarefwkservice/test/fuzztest/componentenable_fuzzer/componentenable_fuzzer.h @@ -18,5 +18,30 @@ #define FUZZ_PROJECT_NAME "componentenable_fuzzer" -#endif +#include +#include "idistributed_hardware_source.h" + +namespace OHOS { +namespace DistributedHardware { +class FuzzDistributedHardwareSource : public IDistributedHardwareSource { +public: + FuzzDistributedHardwareSource() = default; + virtual ~FuzzDistributedHardwareSource() = default; + + int32_t InitSource(const std::string&) override; + int32_t ReleaseSource() override; + int32_t RegisterDistributedHardware(const std::string&, const std::string&, + const EnableParam&, std::shared_ptr) override; + int32_t UnregisterDistributedHardware(const std::string&, const std::string&, + std::shared_ptr callback) override; + int32_t ConfigDistributedHardware(const std::string&, const std::string&, const std::string&, + const std::string&) override; + void RegisterDistributedHardwareStateListener(std::shared_ptr) override; + void UnregisterDistributedHardwareStateListener() override{} + void RegisterDataSyncTriggerListener(std::shared_ptr) override; + void UnregisterDataSyncTriggerListener() override{} +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif diff --git a/services/distributedhardwarefwkservice/test/fuzztest/dhcommtool_fuzzer/dhcommtool_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/dhcommtool_fuzzer/dhcommtool_fuzzer.cpp index 7e7e71b6..ee4a5112 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/dhcommtool_fuzzer/dhcommtool_fuzzer.cpp +++ b/services/distributedhardwarefwkservice/test/fuzztest/dhcommtool_fuzzer/dhcommtool_fuzzer.cpp @@ -68,6 +68,77 @@ void DhTransportParseAndSaveRemoteDHCapsFuzzTest(const uint8_t* data, size_t siz std::shared_ptr dhCommTool = std::make_shared(); dhCommTool->ParseAndSaveRemoteDHCaps(remoteCaps); } + +void DhTransportInitFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::shared_ptr dhCommTool = std::make_shared(); + dhCommTool->Init(); +} + +void DhTransportUnInitFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::shared_ptr dhCommTool = std::make_shared(); + dhCommTool->UnInit(); +} + +void DHCommToolEventHandlerCtorFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + auto runner = AppExecFwk::EventRunner::Create(true); + std::shared_ptr commToolPtr; + DHCommTool::DHCommToolEventHandler handler(runner, commToolPtr); +} + +void DHCommToolEventHandlerProcessEventFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + auto runner = AppExecFwk::EventRunner::Create(true); + auto commTool = std::make_shared(); + auto handler = std::make_shared(runner, commTool); + + uint32_t eventId = (size > 0) ? data[0] % 4 : 0; + + auto event = AppExecFwk::InnerEvent::Get(eventId); + handler->ProcessEvent(event); + auto eventNoMsg = AppExecFwk::InnerEvent::Get(eventId); + handler->ProcessEvent(eventNoMsg); +} + +void DHCommToolEventHandlerProcessFullCapsRspFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + auto runner = AppExecFwk::EventRunner::Create(true); + auto commTool = std::make_shared(); + DHCommTool::DHCommToolEventHandler handler(runner, commTool); + + FullCapsRsp capsRsp; + handler.ProcessFullCapsRsp(capsRsp, commTool); + + capsRsp.networkId = "fuzz_network"; + handler.ProcessFullCapsRsp(capsRsp, commTool); + + auto capInfo = std::make_shared(); + capsRsp.caps.push_back(capInfo); + handler.ProcessFullCapsRsp(capsRsp, nullptr); + + auto commToolNoTrans = std::make_shared(); + handler.ProcessFullCapsRsp(capsRsp, commToolNoTrans); + + commTool->Init(); + handler.ProcessFullCapsRsp(capsRsp, commTool); +} } } @@ -79,6 +150,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::DistributedHardware::DhTransportTriggerReqFullDHCapsFuzzTest(data, size); OHOS::DistributedHardware::DhTransportGetAndSendLocalFullCapsFuzzTest(data, size); OHOS::DistributedHardware::DhTransportParseAndSaveRemoteDHCapsFuzzTest(data, size); + OHOS::DistributedHardware::DhTransportInitFuzzTest(data, size); + OHOS::DistributedHardware::DhTransportUnInitFuzzTest(data, size); + OHOS::DistributedHardware::DHCommToolEventHandlerCtorFuzzTest(data, size); + OHOS::DistributedHardware::DHCommToolEventHandlerProcessEventFuzzTest(data, size); + OHOS::DistributedHardware::DHCommToolEventHandlerProcessFullCapsRspFuzzTest(data, size); return 0; } diff --git a/services/distributedhardwarefwkservice/test/fuzztest/dhtransport_fuzzer/dhtransport_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/dhtransport_fuzzer/dhtransport_fuzzer.cpp index 70c9e399..ce7b16ec 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/dhtransport_fuzzer/dhtransport_fuzzer.cpp +++ b/services/distributedhardwarefwkservice/test/fuzztest/dhtransport_fuzzer/dhtransport_fuzzer.cpp @@ -35,6 +35,13 @@ namespace DistributedHardware { namespace { const int32_t SOCKETID = 1; } + +void OnBind(int32_t socket, PeerSocketInfo info); +void OnShutdown(int32_t socket, ShutdownReason reason); +void OnBind(int32_t socket, PeerSocketInfo info); +void OnBytes(int32_t socket, const void *data, uint32_t dataLen); +std::shared_ptr GetDHCommToolPtr(); + void DhTransportOnBytesReceivedFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(int32_t))) { @@ -160,6 +167,67 @@ void DhTransportOnSocketClosedFuzzTest(const uint8_t* data, size_t size) dhTransportTest->OnSocketClosed(socketId, reason); dhTransportTest->UnInit(); } + +void DhTransportOnBindFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t socketId = fdp.ConsumeIntegral(); + std::string peerSocketName = fdp.ConsumeRandomLengthString(); + std::string remoteNetworkId = fdp.ConsumeRandomLengthString(); + PeerSocketInfo info = { + .name = const_cast(peerSocketName.c_str()), + .networkId = const_cast(remoteNetworkId.c_str()), + .pkgName = const_cast(DH_FWK_PKG_NAME.c_str()), + .dataType = DATA_TYPE_BYTES + }; + std::shared_ptr dhCommTool = std::make_shared(); + std::shared_ptr dhTransportTest = std::make_shared(dhCommTool); + OnBind(socketId, info); +} + +void DhTransportOnShutdownFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + int32_t socketId = *(reinterpret_cast(data)); + ShutdownReason reason = ShutdownReason::SHUTDOWN_REASON_UNKNOWN; + std::shared_ptr dhCommTool = std::make_shared(); + std::shared_ptr dhTransportTest = std::make_shared(dhCommTool); + OnShutdown(socketId, reason); + dhTransportTest->UnInit(); +} + +void DhTransportInitFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + std::shared_ptr dhCommTool = std::make_shared(); + std::shared_ptr dhTransportTest = std::make_shared(dhCommTool); + dhTransportTest->Init(); +} + +void DhTransportOnBytesFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + int32_t socketId = *(reinterpret_cast(data)); + uint32_t dataLen = *(reinterpret_cast(data + sizeof(int32_t))); + OnBytes(socketId, data, dataLen); +} + +void DhTransportGetDHCommToolPtrFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + auto ptr = GetDHCommToolPtr(); +} } } @@ -176,6 +244,11 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::DistributedHardware::DhTransportSendFuzzTest(data, size); OHOS::DistributedHardware::DhTransportOnSocketOpenedFuzzTest(data, size); OHOS::DistributedHardware::DhTransportOnSocketClosedFuzzTest(data, size); + OHOS::DistributedHardware::DhTransportOnBindFuzzTest(data, size); + OHOS::DistributedHardware::DhTransportOnShutdownFuzzTest(data, size); + OHOS::DistributedHardware::DhTransportInitFuzzTest(data, size); + OHOS::DistributedHardware::DhTransportOnBytesFuzzTest(data, size); + OHOS::DistributedHardware::DhTransportGetDHCommToolPtrFuzzTest(data, size); return 0; } -- Gitee From 7b805e9459204a95109f937f9546fd3dee29fa31 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 19 Jun 2025 20:39:20 +0800 Subject: [PATCH 02/10] add FUZZ Signed-off-by: BrainL --- .../hardwarestatuslistenerstub_fuzzer.cpp | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp index 70757c1c..05fff025 100644 --- a/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp +++ b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp @@ -52,10 +52,9 @@ void HDSinkStatusOnRemoteRequestFuzzTest(const uint8_t *data, size_t size) } FuzzHDSinkStatusListenerStub stub; - stub.OnRemoteRequest(code, parcel, reply, option); - } + void HDSourceStatusOnRemoteRequestFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size < sizeof(uint32_t))) { @@ -76,7 +75,6 @@ void HDSourceStatusOnRemoteRequestFuzzTest(const uint8_t *data, size_t size) code = *(reinterpret_cast(data)); } FuzzHDSourceStatusListenerStub stub; - stub.OnRemoteRequest(code, parcel, reply, option); } } // namespace DistributedHardware -- Gitee From 43290721145da3ef31910afb01d84b9a17daba1f Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 19 Jun 2025 21:04:27 +0800 Subject: [PATCH 03/10] add FUZZ Signed-off-by: BrainL --- .../test/fuzztest/accessmanager_fuzzer/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/services/distributedhardwarefwkservice/test/fuzztest/accessmanager_fuzzer/BUILD.gn b/services/distributedhardwarefwkservice/test/fuzztest/accessmanager_fuzzer/BUILD.gn index 76542cac..98ae5286 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/accessmanager_fuzzer/BUILD.gn +++ b/services/distributedhardwarefwkservice/test/fuzztest/accessmanager_fuzzer/BUILD.gn @@ -34,6 +34,7 @@ ohos_fuzztest("AccessManagerFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", + "-Dprivate=public", ] sources = [ "accessmanager_fuzzer.cpp" ] -- Gitee From 6a875da5209474c8585c8eac89f9a6ef798a5be9 Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 19 Jun 2025 22:00:17 +0800 Subject: [PATCH 04/10] add FUZZ Signed-off-by: BrainL --- .../test/fuzztest/distributedhardwarefwkkit_fuzzer/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/BUILD.gn b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/BUILD.gn index f2d874b4..ebbd5ab2 100644 --- a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/BUILD.gn +++ b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/BUILD.gn @@ -39,6 +39,7 @@ ohos_fuzztest("DistributedHardwareFwkKitFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", + "-Dprivate=public", ] sources = [ "distributedhardwarefwkkit_fuzzer.cpp" ] -- Gitee From 1385ccc47e1e6e1fd7dd6fe404d88be236559aea Mon Sep 17 00:00:00 2001 From: BrainL Date: Thu, 19 Jun 2025 23:15:59 +0800 Subject: [PATCH 05/10] add FUZZ Signed-off-by: BrainL --- .../getdhdescriptorscallbackstub_fuzzer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.cpp b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.cpp index a613f010..642eef5e 100644 --- a/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.cpp +++ b/interfaces/inner_kits/test/fuzztest/getdhdescriptorscallbackstub_fuzzer/getdhdescriptorscallbackstub_fuzzer.cpp @@ -26,7 +26,6 @@ #include "constants.h" #include "dhardware_descriptor.h" #include "distributed_hardware_errno.h" -#include "distributed_hardware_log.h" #include "get_dh_descriptors_callback_stub.h" #include "publisher_listener_stub.h" -- Gitee From cb866986f2ce79b6dd2ab2a06704bdb9af5b7e5d Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 20 Jun 2025 18:03:14 +0800 Subject: [PATCH 06/10] add FUZZ Signed-off-by: BrainL --- interfaces/inner_kits/test/fuzztest/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/interfaces/inner_kits/test/fuzztest/BUILD.gn b/interfaces/inner_kits/test/fuzztest/BUILD.gn index 2e759f50..f9e2fe6f 100644 --- a/interfaces/inner_kits/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/test/fuzztest/BUILD.gn @@ -18,5 +18,6 @@ group("fuzztest") { "distributedhardwarefwkkit_fuzzer:fuzztest", "distributedhardwarefwkstub_fuzzer:fuzztest", "getdhdescriptorscallbackstub_fuzzer:fuzztest", + "hardwarestatuslistenerstub_fuzzer:fuzztest", ] } -- Gitee From b75de971ccc859d69708075fc13bdde271c91182 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 20 Jun 2025 19:16:22 +0800 Subject: [PATCH 07/10] add FUZZ Signed-off-by: BrainL --- .../hardwarestatuslistenerstub_fuzzer.cpp | 1 - 1 file changed, 1 deletion(-) diff --git a/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp index 05fff025..ee90ad53 100644 --- a/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp +++ b/interfaces/inner_kits/test/fuzztest/hardwarestatuslistenerstub_fuzzer/hardwarestatuslistenerstub_fuzzer.cpp @@ -26,7 +26,6 @@ #include "constants.h" #include "dhardware_descriptor.h" #include "distributed_hardware_errno.h" -#include "distributed_hardware_log.h" #include "hardware_status_listener_stub.h" #include "publisher_listener_stub.h" -- Gitee From 7aa9d90054ccc1b8533a8b0c9651f52d73020947 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 20 Jun 2025 20:24:13 +0800 Subject: [PATCH 08/10] add FUZZ Signed-off-by: BrainL --- .../test/fuzztest/accessmanager_fuzzer/accessmanager_fuzzer.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/services/distributedhardwarefwkservice/test/fuzztest/accessmanager_fuzzer/accessmanager_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/accessmanager_fuzzer/accessmanager_fuzzer.cpp index 4d4d8f92..339cc163 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/accessmanager_fuzzer/accessmanager_fuzzer.cpp +++ b/services/distributedhardwarefwkservice/test/fuzztest/accessmanager_fuzzer/accessmanager_fuzzer.cpp @@ -172,6 +172,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::DistributedHardware::OnDeviceOnlineFuzzTest(data, size); OHOS::DistributedHardware::OnDeviceChangedFuzzTest(data, size); OHOS::DistributedHardware::UnInitFuzzTest(data, size); + OHOS::DistributedHardware::UnInitDeviceManagerFuzzTest(data, size); + OHOS::DistributedHardware::UnRegisterDevStateCallbackFuzzTest(data, size); OHOS::DistributedHardware::OnRemoteDiedFuzzTest(data, size); OHOS::DistributedHardware::CheckTrustedDeviceOnlineFuzzTest(data, size); OHOS::DistributedHardware::DumpFuzzTest(data, size); -- Gitee From 39c89778550fe1a14287de3b9a2c203b26b24b74 Mon Sep 17 00:00:00 2001 From: BrainL Date: Fri, 20 Jun 2025 20:42:39 +0800 Subject: [PATCH 09/10] add FUZZ Signed-off-by: BrainL --- .../distributedhardwarefwkkit_fuzzer.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.cpp b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.cpp index b9ed0225..ba39bd28 100644 --- a/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.cpp +++ b/interfaces/inner_kits/test/fuzztest/distributedhardwarefwkkit_fuzzer/distributedhardwarefwkkit_fuzzer.cpp @@ -403,7 +403,7 @@ void IsQueryLocalSysSpecTypeValidFuzzTest(const uint8_t *data, size_t size) dhfwkKit.IsQueryLocalSysSpecTypeValid(specType); } -void RegisterCtlCenterCallback(const uint8_t *data, size_t size) +void RegisterCtlCenterCallbackFuzzTest(const uint8_t *data, size_t size) { if ((data == nullptr) || (size == 0)) { return; @@ -445,6 +445,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) OHOS::DistributedHardware::RegisterDHStatusListenerOneParamFuzzTest(data, size); OHOS::DistributedHardware::UnregisterDHStatusListenerOneParamFuzzTest(data, size); OHOS::DistributedHardware::IsQueryLocalSysSpecTypeValidFuzzTest(data, size); - OHOS::DistributedHardware::RegisterCtlCenterCallback(data, size); + OHOS::DistributedHardware::RegisterCtlCenterCallbackFuzzTest(data, size); return 0; } \ No newline at end of file -- Gitee From acf6c21d7bd75003afc5b44fe5c04e7d82f58512 Mon Sep 17 00:00:00 2001 From: BrainL Date: Sat, 21 Jun 2025 17:49:20 +0800 Subject: [PATCH 10/10] add FUZZ Signed-off-by: BrainL --- .../test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.cpp | 2 +- .../test/fuzztest/dhtransport_fuzzer/dhtransport_fuzzer.cpp | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.cpp b/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.cpp index 68795319..772754b5 100644 --- a/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.cpp +++ b/av_transport/framework/filter/test/fuzztest/filterfactory_fuzzer/filterfactory_fuzzer.cpp @@ -26,7 +26,7 @@ void FilterFactoryFuzzerTest(const uint8_t *data, size_t size) return; } std::string filterName(reinterpret_cast(data), size - 1); - FilterType type = static_cast(data[size - 1]); + FilterType type = FilterType::FILTERTYPE_SOURCE; auto filter = FilterFactory::Instance().CreateFilterPriv(filterName, type); } } // namespace Pipeline diff --git a/services/distributedhardwarefwkservice/test/fuzztest/dhtransport_fuzzer/dhtransport_fuzzer.cpp b/services/distributedhardwarefwkservice/test/fuzztest/dhtransport_fuzzer/dhtransport_fuzzer.cpp index ce7b16ec..8c1329d6 100644 --- a/services/distributedhardwarefwkservice/test/fuzztest/dhtransport_fuzzer/dhtransport_fuzzer.cpp +++ b/services/distributedhardwarefwkservice/test/fuzztest/dhtransport_fuzzer/dhtransport_fuzzer.cpp @@ -213,7 +213,7 @@ void DhTransportInitFuzzTest(const uint8_t* data, size_t size) void DhTransportOnBytesFuzzTest(const uint8_t* data, size_t size) { - if ((data == nullptr) || (size < sizeof(int32_t))) { + if ((data == nullptr) || (size < sizeof(int32_t) + sizeof(uint32_t))) { return; } int32_t socketId = *(reinterpret_cast(data)); -- Gitee