diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 588e4a1a5b9d90073755bd0fc599b52929649499..50d014801b7eb8b70f8c13992281888aa74d12fc 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 0000000000000000000000000000000000000000..d56fa2b9bc1405b164711cc4d63e1ace9e0f01d4 --- /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 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /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 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /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 0000000000000000000000000000000000000000..4506ec0d0ade89fadff6843be3bf80ed730b6855 --- /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 0000000000000000000000000000000000000000..62825e5591ad69df6d92468674a4be141768f513 --- /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 0000000000000000000000000000000000000000..7223f1432c8af67ccc1e3f3fa45220fde5ea641e --- /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 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /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 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /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 0000000000000000000000000000000000000000..0da44199142712884acf468859302d6ca71249ac --- /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 0000000000000000000000000000000000000000..24bebe338b4c8230b846edaae48c1cc992819685 --- /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 0000000000000000000000000000000000000000..399a6eba58b7ba349fe8efe9d1aea3eef0fbc2ac --- /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 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /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 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /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 0000000000000000000000000000000000000000..b5ff478ac696e88f961947d546acf5e8876e5da7 --- /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 0000000000000000000000000000000000000000..aead1565b2b8cf2437983bd8f86508463568af88 --- /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 0000000000000000000000000000000000000000..34194f275601fe93f9b56073671bf1388feeb1d1 --- /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 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /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 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /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 0000000000000000000000000000000000000000..711d0432f5dac398c7d8edcd363f24aab1b3e792 --- /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 0000000000000000000000000000000000000000..22d522a2a7cb6e17fcb498f29c866ec9e552b410 --- /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 0000000000000000000000000000000000000000..2843357e531c36330baa451d152177d948285c34 --- /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 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /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 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /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 0000000000000000000000000000000000000000..b28186d775e654be5c151b3871b2aefb22b5a2e5 --- /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 0000000000000000000000000000000000000000..ee2f7003fa0a8185d2c5542524e074188469e689 --- /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 0000000000000000000000000000000000000000..0002af03318e0c1e13023d29ef64571cbc4c2b81 --- /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 0000000000000000000000000000000000000000..6198079a28e860189d4294f6598f8ac6804c0dff --- /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 0000000000000000000000000000000000000000..7133b2b92440904a5ed04b838733acea0f97486a --- /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 0000000000000000000000000000000000000000..994223664f69b6743c9ac4a27b03634816257609 --- /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 0000000000000000000000000000000000000000..a00a5c2aeb8144cc32b11f14f64fa78efd7a600f --- /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 0000000000000000000000000000000000000000..95fcd06c229544f35404e39c4f95fe76c7b3b661 --- /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