diff --git a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn index f4754e413f2ce42b202317c042a1cb96404ae4c3..fcc2a5f1e232a0f43a02bded4b535401b7be33c5 100644 --- a/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/inner_kits/native_cpp/test/fuzztest/BUILD.gn @@ -35,6 +35,7 @@ group("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", + "${services_path}/audiomanager/test/fuzztest/sinkservicedump_fuzzer:fuzztest", "${services_path}/common/test/fuzztest/audiodatasetinit64_fuzzer:fuzztest", "onremotesinksvrdied_fuzzer:fuzztest", "onremotesourcesvrdied_fuzzer:fuzztest", diff --git a/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/BUILD.gn b/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..7fcf18a37a6387764bceb397106d130b52250dd8 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/BUILD.gn @@ -0,0 +1,67 @@ +# Copyright (c) 2022 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("SinkServiceDumpFuzzTest") { + module_out_path = "${distributedaudio_fuzz_path}/sinkservicedump_fuzzer" + fuzz_config_file = + "${services_path}/audiomanager/test/fuzztest/sinkservicedump_fuzzer" + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "sinkservicedump_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=\"SinkServiceDumpFuzzTest\"", + "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 = [ ":SinkServiceDumpFuzzTest" ] +} +############################################################################### diff --git a/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/corpus/init b/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2022 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/sinkservicedump_fuzzer/project.xml b/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/sinkservicedump_fuzzer.cpp b/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/sinkservicedump_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..65ef97820a4d37caaa2dd0c1737f0eccff2d0c69 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/sinkservicedump_fuzzer.cpp @@ -0,0 +1,58 @@ +/* + * Copyright (c) 2022 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 "sinkservicedump_fuzzer.h" + +#include +#include +#include + +#include "daudio_sink_service.h" +#include "daudio_sink_ipc_callback.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +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(fd, true); + dAudioSinkService->Dump(fd, args); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SinkServiceDumpFuzzTest(data, size); + return 0; +} + diff --git a/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/sinkservicedump_fuzzer.h b/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/sinkservicedump_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..c30a3f4f0f0be4533fab754f1f48bb7986caf902 --- /dev/null +++ b/services/audiomanager/test/fuzztest/sinkservicedump_fuzzer/sinkservicedump_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2022 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 SINKSERVICEDUMP_FUZZER_H +#define SINKSERVICEDUMP_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkservicedump_fuzzer" + +#endif \ No newline at end of file