From 4055a5e208f1b831b62fc2ec61600dcd23f3b153 Mon Sep 17 00:00:00 2001 From: chen0088 Date: Tue, 6 Feb 2024 11:21:46 +0800 Subject: [PATCH] add fuzz Signed-off-by: chen0088 --- .../native_cpp/test/fuzztest/BUILD.gn | 6 ++ .../BUILD.gn | 63 ++++++++++++++++ .../corpus/init | 16 +++++ .../project.xml | 25 +++++++ ...handlerpausedistributedhardware_fuzzer.cpp | 41 +++++++++++ ...nkhandlerpausedistributedhardware_fuzzer.h | 21 ++++++ .../BUILD.gn | 71 +++++++++++++++++++ .../corpus/init | 16 +++++ .../project.xml | 25 +++++++ ...handlerregisterprivacyresources_fuzzer.cpp | 41 +++++++++++ ...nkhandlerregisterprivacyresources_fuzzer.h | 21 ++++++ .../BUILD.gn | 63 ++++++++++++++++ .../corpus/init | 16 +++++ .../project.xml | 25 +++++++ ...andlerresumedistributedhardware_fuzzer.cpp | 41 +++++++++++ ...khandlerresumedistributedhardware_fuzzer.h | 21 ++++++ .../BUILD.gn | 63 ++++++++++++++++ .../corpus/init | 16 +++++ .../project.xml | 25 +++++++ ...khandlerstopdistributedhardware_fuzzer.cpp | 41 +++++++++++ ...inkhandlerstopdistributedhardware_fuzzer.h | 21 ++++++ .../BUILD.gn | 66 +++++++++++++++++ .../corpus/init | 16 +++++ .../project.xml | 25 +++++++ ...ipccallbackonnotifyresourceinfo_fuzzer.cpp | 55 ++++++++++++++ ...nkipccallbackonnotifyresourceinfo_fuzzer.h | 21 ++++++ .../BUILD.gn | 66 +++++++++++++++++ .../corpus/init | 16 +++++ .../project.xml | 25 +++++++ .../sinkipccallbackonremoterequest_fuzzer.cpp | 71 +++++++++++++++++++ .../sinkipccallbackonremoterequest_fuzzer.h | 21 ++++++ .../include/mock_component_resourceinfo.h | 43 +++++++++++ 32 files changed, 1103 insertions(+) create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/BUILD.gn create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/corpus/init create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/project.xml create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.cpp create mode 100644 interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.h create mode 100644 interfaces/inner_kits/native_cpp/test/include/mock_component_resourceinfo.h diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 588e4a1a..50d01480 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -35,8 +35,14 @@ group("fuzztest") { "onremotesourcesvrdied_fuzzer:fuzztest", "sinkhandlerfinishstartsa_fuzzer:fuzztest", "sinkhandlerinitsink_fuzzer:fuzztest", + "sinkhandlerpausedistributedhardware_fuzzer:fuzztest", + "sinkhandlerregisterprivacyresources_fuzzer:fuzztest", + "sinkhandlerresumedistributedhardware_fuzzer:fuzztest", + "sinkhandlerstopdistributedhardware_fuzzer:fuzztest", "sinkhandlersubscribelocalhardware_fuzzer:fuzztest", "sinkhandlerunsubscribelocalhardware_fuzzer:fuzztest", + "sinkipccallbackonnotifyresourceinfo_fuzzer:fuzztest", + "sinkipccallbackonremoterequest_fuzzer:fuzztest", "sinkonloadsystemabilityfail_fuzzer:fuzztest", "sinkonloadsystemabilitysuccess_fuzzer:fuzztest", "sinkproxydaudionotify_fuzzer:fuzztest", diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 00000000..d56fa2b9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,63 @@ +# 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("SinkHandlerPauseDistributedHardwareFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkhandlerpausedistributedhardware" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkhandlerpausedistributedhardware_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" ] + + external_deps = [ "c_utils:utils" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkHandlerPauseDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkHandlerPauseDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/corpus/init new file mode 100644 index 00000000..6198079a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_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/sinkhandlerpausedistributedhardware_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.cpp new file mode 100644 index 00000000..4506ec0d --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * 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 "sinkhandlerpausedistributedhardware_fuzzer.h" + +#include "daudio_sink_handler.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkHandlerPauseDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string networkId(reinterpret_cast(data), size); + + DAudioSinkHandler::GetInstance().PauseDistributedHardware(networkId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkHandlerPauseDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_fuzzer.h new file mode 100644 index 00000000..62825e55 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerpausedistributedhardware_fuzzer/sinkhandlerpausedistributedhardware_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 SINKHANDLERPAUSEDISTRIBUTEDHARDWARE_FUZZER_H +#define SINKHANDLERPAUSEDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkhandlerpausedistributedhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn new file mode 100644 index 00000000..7223f143 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/BUILD.gn @@ -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. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkHandlerRegisterPrivacyResourcesFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkhandlerregisterprivacyresources" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkhandlerregisterprivacyresources_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", + "${innerkits_path}/native_cpp/test/include", + "${fwk_services_path}/distributedhardwarefwkservice/include", + "${fwk_services_path}/distributedhardwarefwkservice/include/componentmanager", + ] + + deps = [ + "${fwk_services_path}/distributedhardwarefwkservice:distributedhardwarefwksvr", + "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkHandlerRegisterPrivacyResourcesFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkHandlerRegisterPrivacyResourcesFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/corpus/init new file mode 100644 index 00000000..6198079a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_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/sinkhandlerregisterprivacyresources_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp new file mode 100644 index 00000000..0da44199 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * 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 "sinkhandlerregisterprivacyresources_fuzzer.h" + +#include "daudio_sink_handler.h" +#include "mock_component_resourceinfo.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkHandlerRegisterPrivacyResourcesFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return; + } + std::shared_ptr listener = std::make_shared(); + DAudioSinkHandler::GetInstance().RegisterPrivacyResources(listener); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkHandlerRegisterPrivacyResourcesFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_fuzzer.h new file mode 100644 index 00000000..24bebe33 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerregisterprivacyresources_fuzzer/sinkhandlerregisterprivacyresources_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 SINKHANDLERREGISTERPRIVACYRESOURCE_FUZZER_H +#define SINKHANDLERREGISTERPRIVACYRESOURCE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkhandlerregisterprivacyresources_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 00000000..399a6eba --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,63 @@ +# 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("SinkHandlerResumeDistributedHardwareFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkhandlerresumedistributedhardware" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkhandlerresumedistributedhardware_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" ] + + external_deps = [ "c_utils:utils" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkHandlerResumeDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkHandlerResumeDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/corpus/init new file mode 100644 index 00000000..6198079a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_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/sinkhandlerresumedistributedhardware_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.cpp new file mode 100644 index 00000000..b5ff478a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * 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 "sinkhandlerresumedistributedhardware_fuzzer.h" + +#include "daudio_sink_handler.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkHandlerResumeDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string networkId(reinterpret_cast(data), size); + + DAudioSinkHandler::GetInstance().ResumeDistributedHardware(networkId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkHandlerResumeDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_fuzzer.h new file mode 100644 index 00000000..aead1565 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerresumedistributedhardware_fuzzer/sinkhandlerresumedistributedhardware_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 SINKHANDLERRESUMEDISTRIBUTEDHARDWARE_FUZZER_H +#define SINKHANDLERRESUMEDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkhandlerresumedistributedhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/BUILD.gn new file mode 100644 index 00000000..34194f27 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/BUILD.gn @@ -0,0 +1,63 @@ +# 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("SinkHandlerStopDistributedHardwareFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkhandlerstopdistributedhardware" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkhandlerstopdistributedhardware_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" ] + + external_deps = [ "c_utils:utils" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkHandlerStopDistributedHardwareFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkHandlerStopDistributedHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/corpus/init new file mode 100644 index 00000000..6198079a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_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/sinkhandlerstopdistributedhardware_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.cpp new file mode 100644 index 00000000..711d0432 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.cpp @@ -0,0 +1,41 @@ +/* + * 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 "sinkhandlerstopdistributedhardware_fuzzer.h" + +#include "daudio_sink_handler.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkHandlerStopDistributedHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string networkId(reinterpret_cast(data), size); + + DAudioSinkHandler::GetInstance().StopDistributedHardware(networkId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkHandlerStopDistributedHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_fuzzer.h new file mode 100644 index 00000000..22d522a2 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkhandlerstopdistributedhardware_fuzzer/sinkhandlerstopdistributedhardware_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 SINKHANDLERSTOPDISTRIBUTEDHARDWARE_FUZZER_H +#define SINKHANDLERSTOPDISTRIBUTEDHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkhandlerstopdistributedhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/BUILD.gn new file mode 100644 index 00000000..2843357e --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/BUILD.gn @@ -0,0 +1,66 @@ +# 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("SinkIpcCallbackOnNotifyResourceInfoFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkipccallbackonnotifyresourceinfo" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkipccallbackonnotifyresourceinfo_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=\"SinkIpcCallbackOnNotifyResourceInfoFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkIpcCallbackOnNotifyResourceInfoFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/corpus/init new file mode 100644 index 00000000..6198079a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_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/sinkipccallbackonnotifyresourceinfo_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.cpp new file mode 100644 index 00000000..b28186d7 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * 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 "sinkipccallbackonnotifyresourceinfo_fuzzer.h" + +#include "daudio_sink_ipc_callback.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 SinkIpcCallbackOnNotifyResourceInfoFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + + ResourceEventType type = 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; + std::shared_ptr callback = std::make_shared(); + + callback->OnNotifyResourceInfo(type, subtype, networkId, isSensitive, isSameAccout); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkIpcCallbackOnNotifyResourceInfoFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_fuzzer.h new file mode 100644 index 00000000..ee2f7003 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonnotifyresourceinfo_fuzzer/sinkipccallbackonnotifyresourceinfo_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 SINKIPCCALLBACKONNOTIFYRESOURCEINFO_FUZZER_H +#define SINKIPCCALLBACKONNOTIFYRESOURCEINFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkipccallbackonnotifyresourceinfo_fuzzer" + +#endif diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/BUILD.gn new file mode 100644 index 00000000..0002af03 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/BUILD.gn @@ -0,0 +1,66 @@ +# 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("SinkIpcCallbackOnRemoteRequestFuzzTest") { + module_out_path = + "${distributedaudio_fuzz_path}/sinkipccallbackonremoterequest" + fuzz_config_file = "${innerkits_path}/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkipccallbackonremoterequest_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=\"SinkIpcCallbackOnRemoteRequestFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "ipc:ipc_core", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkIpcCallbackOnRemoteRequestFuzzTest" ] +} +############################################################################### diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/corpus/init b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/corpus/init new file mode 100644 index 00000000..6198079a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_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/sinkipccallbackonremoterequest_fuzzer/project.xml b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/project.xml new file mode 100644 index 00000000..7133b2b9 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.cpp b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.cpp new file mode 100644 index 00000000..99422366 --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_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 "sinkipccallbackonremoterequest_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 SinkIpcCallbackOnRemoteRequestFuzzTest(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->OnRemoteRequest(code, pdata, reply, option); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkIpcCallbackOnRemoteRequestFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.h b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_fuzzer.h new file mode 100644 index 00000000..a00a5c2a --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/sinkipccallbackonremoterequest_fuzzer/sinkipccallbackonremoterequest_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 SINKIPCCALLBACKONREMEOTREQUEST_FUZZER_H +#define SINKIPCCALLBACKONREMEOTREQUEST_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkipccallbackonremoterequest_fuzzer" + +#endif diff --git a/interfaces/inner_kits/native_cpp/test/include/mock_component_resourceinfo.h b/interfaces/inner_kits/native_cpp/test/include/mock_component_resourceinfo.h new file mode 100644 index 00000000..95fcd06c --- /dev/null +++ b/interfaces/inner_kits/native_cpp/test/include/mock_component_resourceinfo.h @@ -0,0 +1,43 @@ +/* + * 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 OHOS_DAUDIO_MOCK_COMPONENT_RESOURCE_INFO_H +#define OHOS_DAUDIO_MOCK_COMPONENT_RESOURCE_INFO_H + +#include "daudio_errorcode.h" +#include "idistributed_hardware_sink.h" + +namespace OHOS { +namespace DistributedHardware { +class MockComponentResourceInfo : public std::enable_shared_from_this, + public PrivacyResourcesListener { +public: + MockComponentResourceInfo() + { + } + + virtual ~MockComponentResourceInfo() + { + } + + int32_t OnPrivaceResourceMessage(const ResourceEventType &type, const std::string &subType, + const std::string &networkId, bool &isSensitive, bool &isSameAccout) override + { + return DH_SUCCESS; + } +}; +} // namespace DistributedHardware +} // namespace OHOS +#endif -- Gitee