From b4117e1943fb4eee5171b10edb29fc4abf94d7e5 Mon Sep 17 00:00:00 2001 From: liuxiaowei42 Date: Fri, 4 Jul 2025 10:34:32 +0800 Subject: [PATCH 1/2] modify FUZZ Signed-off-by: liuxiaowei42 --- .../native_cpp/test/fuzztest/BUILD.gn | 3 + .../sinkserviceinitsink_fuzzer.cpp | 67 ----------------- .../sinkserviceonstop_fuzzer/BUILD.gn | 67 +++++++++++++++++ .../sinkserviceonstop_fuzzer/corpus/init | 16 +++++ .../sinkserviceonstop_fuzzer/project.xml | 25 +++++++ .../sinkserviceonstop_fuzzer.cpp | 49 +++++++++++++ .../sinkserviceonstop_fuzzer.h | 21 ++++++ .../sourceservicedaudionotify_fuzzer.cpp | 66 ----------------- .../sourceservicedump_fuzzer/BUILD.gn | 72 +++++++++++++++++++ .../sourceservicedump_fuzzer/corpus/init | 16 +++++ .../sourceservicedump_fuzzer/project.xml | 25 +++++++ .../sourceservicedump_fuzzer.cpp | 55 ++++++++++++++ .../sourceservicedump_fuzzer.h | 21 ++++++ .../sourceserviceonstop_fuzzer/BUILD.gn | 72 +++++++++++++++++++ .../sourceserviceonstop_fuzzer/corpus/init | 16 +++++ .../sourceserviceonstop_fuzzer/project.xml | 25 +++++++ .../sourceserviceonstop_fuzzer.cpp | 49 +++++++++++++ .../sourceserviceonstop_fuzzer.h | 21 ++++++ 18 files changed, 553 insertions(+), 133 deletions(-) create mode 100644 services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/BUILD.gn create mode 100644 services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/corpus/init create mode 100644 services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/project.xml create mode 100644 services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.cpp create mode 100644 services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.h create mode 100644 services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/BUILD.gn create mode 100644 services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/corpus/init create mode 100644 services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/project.xml create mode 100644 services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.cpp create mode 100644 services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.h create mode 100644 services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/BUILD.gn create mode 100644 services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/corpus/init create mode 100644 services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/project.xml create mode 100644 services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.cpp create mode 100644 services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.h diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 9c6060da..196ea570 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -21,6 +21,7 @@ group("fuzztest") { deps = [ "${services_path}/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkservicepausedistributedhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkserviceresumedistributedhardware_fuzzer:fuzztest", @@ -31,7 +32,9 @@ group("fuzztest") { "${services_path}/audiomanager/test/fuzztest/sinkstubonremoterequest_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceserviceconfigdistributedhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceservicedump_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceserviceunregisterdistributedhardware_fuzzer:fuzztest", diff --git a/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp index 72d70e2b..cab6d723 100644 --- a/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp +++ b/services/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer/sinkserviceinitsink_fuzzer.cpp @@ -43,69 +43,6 @@ void SinkServiceInitSinkFuzzTest(const uint8_t* data, size_t size) dAudioSinkService->InitSink(params, dAudioSinkIpcCallback); } - -void SinkServiceOnStartFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return; - } - - FuzzedDataProvider fdp(data, size); - int32_t saId = fdp.ConsumeIntegral(); - bool runOnCreate = fdp.ConsumeBool(); - - auto dAudioSinkService = std::make_shared(saId, runOnCreate); - dAudioSinkService->OnStart(); -} - -void SinkServiceOnStopFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return; - } - - FuzzedDataProvider fdp(data, size); - int32_t saId = fdp.ConsumeIntegral(); - bool runOnCreate = fdp.ConsumeBool(); - - auto dAudioSinkService = std::make_shared(saId, runOnCreate); - dAudioSinkService->OnStop(); -} - -void SinkServiceInitFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return; - } - - FuzzedDataProvider fdp(data, size); - int32_t saId = fdp.ConsumeIntegral(); - bool runOnCreate = fdp.ConsumeBool(); - - auto dAudioSinkService = std::make_shared(saId, runOnCreate); - dAudioSinkService->Init(); -} - -void SinkServiceDumpFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size == 0) { - return; - } - - FuzzedDataProvider fdp(data, size); - int32_t fd = fdp.ConsumeIntegral(); - size_t argsCount = fdp.ConsumeIntegralInRange(0, 10); - std::vector args; - - for (size_t i = 0; i < argsCount; ++i) { - std::string utf8Str = fdp.ConsumeRandomLengthString(100); - std::u16string utf16Str(utf8Str.begin(), utf8Str.end()); - args.emplace_back(utf16Str); - } - - auto dAudioSinkService = std::make_shared(DISTRIBUTED_HARDWARE_AUDIO_SINK_SA_ID, true); - dAudioSinkService->Dump(fd, args); -} } } @@ -114,10 +51,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::SinkServiceInitSinkFuzzTest(data, size); - OHOS::DistributedHardware::SinkServiceOnStartFuzzTest(data, size); - OHOS::DistributedHardware::SinkServiceOnStopFuzzTest(data, size); - OHOS::DistributedHardware::SinkServiceInitFuzzTest(data, size); - OHOS::DistributedHardware::SinkServiceDumpFuzzTest(data, size); return 0; } diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/BUILD.gn new file mode 100644 index 00000000..0f4bf45a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/BUILD.gn @@ -0,0 +1,67 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkServiceOnStopFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sinkserviceonstop_fuzzer" + fuzz_config_file = + "${services_path}/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sinkserviceonstop_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${services_path}/audiomanager/servicesink/include", + ] + + deps = [ + "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", + "${services_path}/audiomanager/servicesink:distributed_audio_sink", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceOnStopFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkServiceOnStopFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/project.xml new file mode 100644 index 00000000..66e1dcac --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.cpp new file mode 100644 index 00000000..c5f2fdfe --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sinkserviceonstop_fuzzer.h" + +#include +#include +#include + +#include "daudio_sink_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkServiceOnStopFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return; + } + + FuzzedDataProvider fdp(data, size); + int32_t saId = fdp.ConsumeIntegral(); + bool runOnCreate = fdp.ConsumeBool(); + + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + dAudioSinkService->OnStop(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkServiceOnStopFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.h b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.h new file mode 100644 index 00000000..e57a7f68 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer/sinkserviceonstop_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SINKSERVICEONSTOP_FUZZER_H +#define SINKSERVICEONSTOP_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkserviceonstop_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.cpp index 925e883a..95da8e4e 100644 --- a/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.cpp +++ b/services/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer/sourceservicedaudionotify_fuzzer.cpp @@ -44,68 +44,6 @@ void SourceServiceDAudioNotifyFuzzTest(const uint8_t* data, size_t size) dAudioSourceService->DAudioNotify(devId, dhId, eventType, eventContent); } - -void SourceServiceOnStartFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return; - } - FuzzedDataProvider fdp(data, size); - - int32_t saId = fdp.ConsumeIntegral(); - bool runOnCreate = fdp.ConsumeBool(); - - auto dAudioSourceService = std::make_shared(saId, runOnCreate); - dAudioSourceService->OnStart(); -} - -void SourceServiceOnStopFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return; - } - FuzzedDataProvider fdp(data, size); - - int32_t saId = fdp.ConsumeIntegral(); - bool runOnCreate = fdp.ConsumeBool(); - - auto dAudioSourceService = std::make_shared(saId, runOnCreate); - dAudioSourceService->OnStop(); -} - -void SourceServiceInitFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size < sizeof(int32_t)) { - return; - } - FuzzedDataProvider fdp(data, size); - - int32_t saId = fdp.ConsumeIntegral(); - bool runOnCreate = fdp.ConsumeBool(); - - auto dAudioSourceService = std::make_shared(saId, runOnCreate); - dAudioSourceService->Init(); -} - -void SourceServiceDumpFuzzTest(const uint8_t* data, size_t size) -{ - if (data == nullptr || size == 0) { - return; - } - FuzzedDataProvider fdp(data, size); - - int32_t fd = fdp.ConsumeIntegral(); - size_t argsCount = fdp.ConsumeIntegralInRange(0, 10); - std::vector args; - for (size_t i = 0; i < argsCount; ++i) { - std::string utf8Str = fdp.ConsumeRandomLengthString(100); - std::u16string utf16Str(utf8Str.begin(), utf8Str.end()); - args.emplace_back(utf16Str); - } - - auto dAudioSourceService = std::make_shared(DISTRIBUTED_HARDWARE_AUDIO_SOURCE_SA_ID, true); - dAudioSourceService->Dump(fd, args); -} } } @@ -114,10 +52,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::SourceServiceDAudioNotifyFuzzTest(data, size); - OHOS::DistributedHardware::SourceServiceOnStartFuzzTest(data, size); - OHOS::DistributedHardware::SourceServiceOnStopFuzzTest(data, size); - OHOS::DistributedHardware::SourceServiceInitFuzzTest(data, size); - OHOS::DistributedHardware::SourceServiceDumpFuzzTest(data, size); return 0; } diff --git a/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/BUILD.gn new file mode 100644 index 00000000..7d43ec5a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceServiceDumpFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sourceservicedump_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceservicedump_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sourceservicedump_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${common_path}/dfx_utils/include", + "${services_path}/common/audioparam", + "${innerkits_path}/native_cpp/audio_source/include", + "${distributedaudio_path}/audiohandler/include", + "${services_path}/audiomanager/servicesource/include", + ] + + deps = + [ "${services_path}/audiomanager/servicesource:distributed_audio_source" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceServiceDumpFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "audio_framework:audio_capturer", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "cJSON:cjson", + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceDumpFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/project.xml new file mode 100644 index 00000000..66e1dcac --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.cpp new file mode 100644 index 00000000..198c7cfd --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.cpp @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sourceservicedump_fuzzer.h" + +#include +#include +#include + +#include "daudio_source_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceDumpFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size == 0) { + return; + } + FuzzedDataProvider fdp(data, size); + + int32_t fd = fdp.ConsumeIntegral(); + size_t argsCount = fdp.ConsumeIntegralInRange(0, 10); + std::vector args; + for (size_t i = 0; i < argsCount; ++i) { + std::string utf8Str = fdp.ConsumeRandomLengthString(100); + std::u16string utf16Str(utf8Str.begin(), utf8Str.end()); + args.emplace_back(utf16Str); + } + + auto dAudioSourceService = std::make_shared(fd, true); + dAudioSourceService->Dump(fd, args); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceDumpFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.h b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.h new file mode 100644 index 00000000..8cb8fc13 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceservicedump_fuzzer/sourceservicedump_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOURCESERVICEDUMP_FUZZER_H +#define SOURCESERVICEDUMP_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceservicedump_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/BUILD.gn new file mode 100644 index 00000000..76a8bcb1 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceServiceOnStopFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sourceserviceonstop_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sourceserviceonstop_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${common_path}/dfx_utils/include", + "${services_path}/common/audioparam", + "${innerkits_path}/native_cpp/audio_source/include", + "${distributedaudio_path}/audiohandler/include", + "${services_path}/audiomanager/servicesource/include", + ] + + deps = + [ "${services_path}/audiomanager/servicesource:distributed_audio_source" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceServiceOnStopFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "audio_framework:audio_capturer", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "cJSON:cjson", + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceOnStopFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/project.xml new file mode 100644 index 00000000..66e1dcac --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.cpp new file mode 100644 index 00000000..97567b2d --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.cpp @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sourceserviceonstop_fuzzer.h" + +#include +#include +#include + +#include "daudio_source_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceOnStopFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return; + } + FuzzedDataProvider fdp(data, size); + + int32_t saId = fdp.ConsumeIntegral(); + bool runOnCreate = fdp.ConsumeBool(); + + auto dAudioSourceService = std::make_shared(saId, runOnCreate); + dAudioSourceService->OnStop(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceOnStopFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.h b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.h new file mode 100644 index 00000000..5a372f5a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer/sourceserviceonstop_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOURCESERVICEONSTOP_FUZZER_H +#define SOURCESERVICEONSTOP_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceserviceonstop_fuzzer" + +#endif \ No newline at end of file -- Gitee From 89712985ba38fc071310594f945e310ca4ac8946 Mon Sep 17 00:00:00 2001 From: liuxiaowei42 Date: Fri, 4 Jul 2025 14:06:43 +0800 Subject: [PATCH 2/2] modify FUZZ Signed-off-by: liuxiaowei42 --- .../native_cpp/test/fuzztest/BUILD.gn | 4 ++ .../fuzztest/sinkserviceinit_fuzzer/BUILD.gn | 67 +++++++++++++++++ .../sinkserviceinit_fuzzer/corpus/init | 16 +++++ .../sinkserviceinit_fuzzer/project.xml | 25 +++++++ .../sinkserviceinit_fuzzer.cpp | 50 +++++++++++++ .../sinkserviceinit_fuzzer.h | 21 ++++++ .../sinkserviceonstart_fuzzer/BUILD.gn | 67 +++++++++++++++++ .../sinkserviceonstart_fuzzer/corpus/init | 16 +++++ .../sinkserviceonstart_fuzzer/project.xml | 25 +++++++ .../sinkserviceonstart_fuzzer.cpp | 50 +++++++++++++ .../sinkserviceonstart_fuzzer.h | 21 ++++++ .../sourceserviceinit_fuzzer/BUILD.gn | 72 +++++++++++++++++++ .../sourceserviceinit_fuzzer/corpus/init | 16 +++++ .../sourceserviceinit_fuzzer/project.xml | 25 +++++++ .../sourceserviceinit_fuzzer.cpp | 50 +++++++++++++ .../sourceserviceinit_fuzzer.h | 21 ++++++ .../sourceserviceonstart_fuzzer/BUILD.gn | 72 +++++++++++++++++++ .../sourceserviceonstart_fuzzer/corpus/init | 16 +++++ .../sourceserviceonstart_fuzzer/project.xml | 25 +++++++ .../sourceserviceonstart_fuzzer.cpp | 50 +++++++++++++ .../sourceserviceonstart_fuzzer.h | 21 ++++++ 21 files changed, 730 insertions(+) create mode 100644 services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/BUILD.gn create mode 100644 services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/corpus/init create mode 100644 services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/project.xml create mode 100644 services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.cpp create mode 100644 services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.h create mode 100644 services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/BUILD.gn create mode 100644 services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/corpus/init create mode 100644 services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/project.xml create mode 100644 services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.cpp create mode 100644 services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.h create mode 100644 services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/BUILD.gn create mode 100644 services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/corpus/init create mode 100644 services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/project.xml create mode 100644 services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.cpp create mode 100644 services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.h create mode 100644 services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/BUILD.gn create mode 100644 services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/corpus/init create mode 100644 services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/project.xml create mode 100644 services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.cpp create mode 100644 services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.h diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index 196ea570..eb3901ee 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -21,6 +21,8 @@ group("fuzztest") { deps = [ "${services_path}/audiomanager/test/fuzztest/sinkservicedaudionotify_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkserviceinitsink_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sinkserviceinit_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkserviceonstop_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkservicepausedistributedhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sinkservicereleasesink_fuzzer:fuzztest", @@ -34,6 +36,8 @@ group("fuzztest") { "${services_path}/audiomanager/test/fuzztest/sourceservicedaudionotify_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceservicedump_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceserviceinitsource_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceserviceinit_fuzzer:fuzztest", + "${services_path}/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceserviceonstop_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceserviceregisterdistributedhardware_fuzzer:fuzztest", "${services_path}/audiomanager/test/fuzztest/sourceservicereleasesource_fuzzer:fuzztest", diff --git a/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/BUILD.gn new file mode 100644 index 00000000..2adc610b --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/BUILD.gn @@ -0,0 +1,67 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkServiceInitFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sinkserviceinit_fuzzer" + fuzz_config_file = + "${services_path}/audiomanager/test/fuzztest/sinkserviceinit_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sinkserviceinit_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${services_path}/audiomanager/servicesink/include", + ] + + deps = [ + "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", + "${services_path}/audiomanager/servicesink:distributed_audio_sink", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceInitFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkServiceInitFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/project.xml new file mode 100644 index 00000000..66e1dcac --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.cpp new file mode 100644 index 00000000..a174cc60 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sinkserviceinit_fuzzer.h" + +#include +#include +#include + +#include "daudio_sink_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkServiceInitFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return; + } + + FuzzedDataProvider fdp(data, size); + int32_t saId = fdp.ConsumeIntegral(); + bool runOnCreate = fdp.ConsumeBool(); + + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + dAudioSinkService->isServiceStarted_ = true; + dAudioSinkService->Init(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkServiceInitFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.h b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.h new file mode 100644 index 00000000..47584fa0 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceinit_fuzzer/sinkserviceinit_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SINKSERVICEINIT_FUZZER_H +#define SINKSERVICEINIT_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkserviceinit_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/BUILD.gn new file mode 100644 index 00000000..29bd66e4 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/BUILD.gn @@ -0,0 +1,67 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkServiceOnStartFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sinkserviceonstart_fuzzer" + fuzz_config_file = + "${services_path}/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sinkserviceonstart_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${innerkits_path}/native_cpp/audio_sink/include", + "${services_path}/audiomanager/servicesink/include", + ] + + deps = [ + "${innerkits_path}/native_cpp/audio_sink:distributed_audio_sink_sdk", + "${services_path}/audiomanager/servicesink:distributed_audio_sink", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SinkServiceOnStartFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SinkServiceOnStartFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/project.xml new file mode 100644 index 00000000..66e1dcac --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.cpp new file mode 100644 index 00000000..649d2192 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sinkserviceonstart_fuzzer.h" + +#include +#include +#include + +#include "daudio_sink_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SinkServiceOnStartFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return; + } + + FuzzedDataProvider fdp(data, size); + int32_t saId = fdp.ConsumeIntegral(); + bool runOnCreate = fdp.ConsumeBool(); + + auto dAudioSinkService = std::make_shared(saId, runOnCreate); + dAudioSinkService->isServiceStarted_ = true; + dAudioSinkService->OnStart(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkServiceOnStartFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.h b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.h new file mode 100644 index 00000000..ebc6212a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkserviceonstart_fuzzer/sinkserviceonstart_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SINKSERVICEONSTART_FUZZER_H +#define SINKSERVICEONSTART_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkserviceonstart_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/BUILD.gn new file mode 100644 index 00000000..7ca0b59a --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceServiceInitFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sourceserviceinit_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceinit_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sourceserviceinit_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${common_path}/dfx_utils/include", + "${services_path}/common/audioparam", + "${innerkits_path}/native_cpp/audio_source/include", + "${distributedaudio_path}/audiohandler/include", + "${services_path}/audiomanager/servicesource/include", + ] + + deps = + [ "${services_path}/audiomanager/servicesource:distributed_audio_source" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceServiceInitFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "audio_framework:audio_capturer", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "cJSON:cjson", + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceInitFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/project.xml new file mode 100644 index 00000000..66e1dcac --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.cpp new file mode 100644 index 00000000..cfb3df1c --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sourceserviceinit_fuzzer.h" + +#include +#include +#include + +#include "daudio_source_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceInitFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return; + } + FuzzedDataProvider fdp(data, size); + + int32_t saId = fdp.ConsumeIntegral(); + bool runOnCreate = fdp.ConsumeBool(); + + auto dAudioSourceService = std::make_shared(saId, runOnCreate); + dAudioSourceService->isServiceStarted_ = true; + dAudioSourceService->Init(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceInitFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.h b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.h new file mode 100644 index 00000000..b5d08a3c --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceinit_fuzzer/sourceserviceinit_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOURCESERVICEINIT_FUZZER_H +#define SOURCESERVICEINIT_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceserviceinit_fuzzer" + +#endif \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/BUILD.gn new file mode 100644 index 00000000..52b55c76 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/BUILD.gn @@ -0,0 +1,72 @@ +# Copyright (c) 2025 Huawei Device Co., Ltd. +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +#####################hydra-fuzz################### +import("//build/config/features.gni") +import("//build/test.gni") +import("../../../../../distributedaudio.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SourceServiceOnStartFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sourceserviceonstart_fuzzer" + fuzz_config_file = "${services_path}/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + sources = [ "sourceserviceonstart_fuzzer.cpp" ] + + include_dirs = [ + "include", + "${common_path}/include", + "${common_path}/dfx_utils/include", + "${services_path}/common/audioparam", + "${innerkits_path}/native_cpp/audio_source/include", + "${distributedaudio_path}/audiohandler/include", + "${services_path}/audiomanager/servicesource/include", + ] + + deps = + [ "${services_path}/audiomanager/servicesource:distributed_audio_source" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"SourceServiceOnStartFuzzTest\"", + "LOG_DOMAIN=0xD004130", + ] + + external_deps = [ + "audio_framework:audio_capturer", + "audio_framework:audio_client", + "audio_framework:audio_renderer", + "cJSON:cjson", + "c_utils:utils", + "distributed_hardware_fwk:distributedhardwareutils", + "drivers_interface_distributed_audio:libdaudio_proxy_1.0", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":SourceServiceOnStartFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/corpus/init new file mode 100644 index 00000000..7ade8a0f --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +FUZZ \ No newline at end of file diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/project.xml new file mode 100644 index 00000000..66e1dcac --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.cpp b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.cpp new file mode 100644 index 00000000..eceafa36 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#include "sourceserviceonstart_fuzzer.h" + +#include +#include +#include + +#include "daudio_source_service.h" + +namespace OHOS { +namespace DistributedHardware { +void SourceServiceOnStartFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size < sizeof(int32_t)) { + return; + } + FuzzedDataProvider fdp(data, size); + + int32_t saId = fdp.ConsumeIntegral(); + bool runOnCreate = fdp.ConsumeBool(); + + auto dAudioSourceService = std::make_shared(saId, runOnCreate); + dAudioSourceService->isServiceStarted_ = true; + dAudioSourceService->OnStart(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SourceServiceOnStartFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.h b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.h new file mode 100644 index 00000000..91b04963 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sourceserviceonstart_fuzzer/sourceserviceonstart_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 Huawei Device Co., Ltd. + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +#ifndef SOURCESERVICEONSTART_FUZZER_H +#define SOURCESERVICEONSTART_FUZZER_H + +#define FUZZ_PROJECT_NAME "sourceserviceonstart_fuzzer" + +#endif \ No newline at end of file -- Gitee