diff --git a/bundle.json b/bundle.json index 1c71c17f11abf3157a1680f959d36d4a0098be32..3250cc91439c7ad8c6a3337be41d285c0e132dc5 100644 --- a/bundle.json +++ b/bundle.json @@ -79,7 +79,9 @@ "test":[ "//foundation/distributedhardware/distributedscreen/services/screentransport/test/unittest:screen_transport_test", "//foundation/distributedhardware/distributedscreen/services/softbusadapter/test/unittest:SoftBusAdapterTest", - "//foundation/distributedhardware/distributedscreen/services/common/test/unittest:service_common_test" + "//foundation/distributedhardware/distributedscreen/services/common/test/unittest:service_common_test", + "//foundation/distributedhardware/distributedscreen/screenhandler/test/fuzztest:fuzztest", + "//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/test/fuzztest:fuzztest" ] } } diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..fd6ed3eebf2201987bfd6c6ca2b87c82a52e58f6 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn @@ -0,0 +1,22 @@ +# 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. + +group("fuzztest") { + testonly = true + + deps = [ + "dscreensinkhandler_fuzzer:fuzztest", + "dscreensinkproxy_fuzzer:fuzztest", + "dscreensourcehandler_fuzzer:fuzztest", + ] +} diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..0d66577372d4db6ad43a13f56a0530ec52750746 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/BUILD.gn @@ -0,0 +1,71 @@ +# 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( + "//foundation/distributedhardware/distributedscreen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DscreenSinkHandlerFuzzTest") { + module_out_path = "distributed_screen/dscreensinkhandler_fuzzer" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${interfaces_path}/innerkits/native_cpp/screen_sink/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dscreen_sink_handler_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_screen_utils", + "${interfaces_path}/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DscreenSinkHandlerFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DscreenSinkHandlerFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/dscreen_sink_handler_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/dscreen_sink_handler_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..66853e0d5b960147e02c987ed5f3b4e6ea1ab0b9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/dscreen_sink_handler_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 "dscreen_sink_handler_fuzzer.h" + +#include +#include + +#include "dscreen_constants.h" +#include "dscreen_sink_handler.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void DscreenSinkHandlerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string params(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string param(reinterpret_cast(data), size); + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID); + wptr remote (remoteObject); + DScreenSinkHandler::GetInstance().InitSink(params); + DScreenSinkHandler::GetInstance().SubscribeLocalHardware(dhId, param); + DScreenSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId); + DScreenSinkHandler::GetInstance().ReleaseSink(); + DScreenSinkHandler::GetInstance().OnRemoteSinkSvrDied(remote); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DscreenSinkHandlerFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/dscreen_sink_handler_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/dscreen_sink_handler_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..2d109e76d4dca871978ad31b5d7ba420a837f76d --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/dscreen_sink_handler_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 DSCREEN_SINK_HANDLER_FUZZER_H +#define DSCREEN_SINK_HANDLER_FUZZER_H + +#define FUZZ_PROJECT_NAME "dscreen_sink_handler_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkhandler_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..3c6054257925901df38f9ce907992afdbdd415f5 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/BUILD.gn @@ -0,0 +1,71 @@ +# 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( + "//foundation/distributedhardware/distributedscreen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DscreenSinkProxyFuzzTest") { + module_out_path = "distributed_screen/dscreensinkproxy_fuzzer" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${interfaces_path}/innerkits/native_cpp/screen_sink/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dscreen_sink_proxy_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_screen_utils", + "${interfaces_path}/innerkits/native_cpp/screen_sink:distributed_screen_sink_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DscreenSinkProxyFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DscreenSinkProxyFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/dscreen_sink_proxy_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/dscreen_sink_proxy_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..2852d9003f0c0ef46346d93c61459f0631d01136 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/dscreen_sink_proxy_fuzzer.cpp @@ -0,0 +1,62 @@ +/* + * 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 "dscreen_sink_proxy_fuzzer.h" + +#include +#include + +#include "dscreen_constants.h" +#include "dscreen_sink_proxy.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void DscreenSinkProxyHandlerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= sizeof(int32_t))) { + return; + } + + std::string params(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string param(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + int32_t eventCode = *(reinterpret_cast(data)); + std::string eventContent(reinterpret_cast(data), size); + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID); + std::shared_ptr dscreenSinkProxy = std::make_shared(remoteObject); + + dscreenSinkProxy->DScreenNotify(devId, eventCode, eventContent); + dscreenSinkProxy->InitSink(params); + dscreenSinkProxy->SubscribeLocalHardware(dhId, param); + dscreenSinkProxy->UnsubscribeLocalHardware(dhId); + dscreenSinkProxy->ReleaseSink(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DscreenSinkProxyHandlerFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/dscreen_sink_proxy_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/dscreen_sink_proxy_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..f6b47fd0ae17e9e32c38895eddb586e68fda691e --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/dscreen_sink_proxy_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 DCREEN_SINK_PROXY_FUZZER_H +#define DCREEN_SINK_PROXY_FUZZER_H + +#define FUZZ_PROJECT_NAME "dscreen_sink_proxy_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensinkproxy_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..1251422236d1f5f879e1ac8574021e9d44a61d59 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# 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( + "//foundation/distributedhardware/distributedscreen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DscreenSourceHandlerFuzzTest") { + module_out_path = "distributed_screen/dscreensourcehandler_fuzzer" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer" + + include_dirs = [ + "//utils/system/safwk/native/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "include/callback", + "${common_path}/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include", + "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", + "${fwk_services_path}/distributedhardwarefwkserviceimpl/include", + "${fwk_services_path}/distributedhardwarefwkserviceimpl/include/componentmanager", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dscreen_source_handler_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_screen_utils", + "${fwk_services_path}/distributedhardwarefwkserviceimpl:distributedhardwarefwksvr_impl", + "${interfaces_path}/innerkits/native_cpp/screen_source:distributed_screen_source_sdk", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DscreenSourceHandlerFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ + "hiviewdfx_hilog_native:libhilog", + "ipc:ipc_core", + "safwk:system_ability_fwk", + "samgr_standard:samgr_proxy", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [ ":DscreenSourceHandlerFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..bc977bd9738ee9a70b362067f57a9c63d3adb801 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/corpus/init @@ -0,0 +1,14 @@ +# 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/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/dscreen_source_handler_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/dscreen_source_handler_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..9bfc6fefa7e2dea52b025a7d1a30676a79cc1c46 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/dscreen_source_handler_fuzzer.cpp @@ -0,0 +1,69 @@ +/* + * 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 "dscreen_source_handler_fuzzer.h" + +#include +#include + +#include "component_disable.h" +#include "component_enable.h" +#include "dscreen_constants.h" +#include "dscreen_source_handler.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void DscreenSourceHandlerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string params(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string key(reinterpret_cast(data), size); + std::string value(reinterpret_cast(data), size); + std::string str(reinterpret_cast(data), size); + EnableParam param; + param.version = str; + param.attrs = str; + std::shared_ptr callback = std::make_shared(); + std::shared_ptr uncallback = std::make_shared(); + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID); + wptr remote (remoteObject); + + DScreenSourceHandler::GetInstance().InitSource(params); + DScreenSourceHandler::GetInstance().RegisterDistributedHardware(devId, dhId, param, callback); + DScreenSourceHandler::GetInstance().ConfigDistributedHardware(devId, dhId, key, value); + DScreenSourceHandler::GetInstance().UnregisterDistributedHardware(devId, dhId, uncallback); + DScreenSourceHandler::GetInstance().ReleaseSource(); + DScreenSourceHandler::GetInstance().OnRemoteSourceSvrDied(remote); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DscreenSourceHandlerFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/dscreen_source_handler_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/dscreen_source_handler_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..60ea167743873074c9a22a12fa0038eca132a102 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/dscreen_source_handler_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 DSCREEN_SOURCE_HANDLER_FUZZER_H +#define DSCREEN_SOURCE_HANDLER_FUZZER_H + +#define FUZZ_PROJECT_NAME "dscreen_source_handler_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourcehandler_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/screenhandler/test/fuzztest/BUILD.gn b/screenhandler/test/fuzztest/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..9c99a47eb31d894917cf48bf2cb0a9c03115dc07 --- /dev/null +++ b/screenhandler/test/fuzztest/BUILD.gn @@ -0,0 +1,18 @@ +# 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. + +group("fuzztest") { + testonly = true + + deps = [ "dscreenhandler_fuzzer:fuzztest" ] +} diff --git a/screenhandler/test/fuzztest/dscreenhandler_fuzzer/BUILD.gn b/screenhandler/test/fuzztest/dscreenhandler_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..a97ffedefd5a64718133e34c09cb452a4328e7d0 --- /dev/null +++ b/screenhandler/test/fuzztest/dscreenhandler_fuzzer/BUILD.gn @@ -0,0 +1,76 @@ +# 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( + "//foundation/distributedhardware/distributedscreen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DscreenHandlerFuzzTest") { + module_out_path = "distributed_screen/dscreenhandler_fuzzer" + + fuzz_config_file = "${distributedscreen_path}/screenhandler/test/fuzztest/dscreenhandler_fuzzer" + + include_dirs = [ + "//third_party/json/include", + "${windowmanager_path}/interfaces/innerkits/dm", + "${mediastandard_path}/interfaces/innerkits/native/media/include", + "${fwk_common_path}/utils/include", + ] + + include_dirs += [ + "include", + "${common_path}/include", + "${distributedscreen_path}/screenhandler/include", + "${fwk_services_path}/distributedhardwarefwkserviceimpl/include/localhardwaremanager", + "//foundation/distributedhardware/distributedhardwarefwk/common/utils/include", + ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dscreen_handler_fuzzer.cpp" ] + + deps = [ + "${common_path}:distributed_screen_utils", + "${distributedscreen_path}/screenhandler:distributed_screen_handler", + "${fwk_services_path}/distributedhardwarefwkserviceimpl:distributedhardwarefwksvr_impl", + "${mediastandard_path}/interfaces/inner_api/native:media_client", + "${windowmanager_path}/dm:libdm", + "//foundation/distributedschedule/samgr/interfaces/innerkits/samgr_proxy:samgr_proxy", + "//foundation/graphic/standard/rosen/modules/render_service_client:librender_service_client", + "//utils/native/base:utils", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DscreenHandlerFuzzTest\"", + "LOG_DOMAIN=0xD004100", + ] + + external_deps = [ "hiviewdfx_hilog_native:libhilog" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + deps = [] + deps += [ ":DscreenHandlerFuzzTest" ] +} +############################################################################### diff --git a/screenhandler/test/fuzztest/dscreenhandler_fuzzer/corpus/init b/screenhandler/test/fuzztest/dscreenhandler_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..8eb5a7d6eb6b7d71f0c70c244e5768d62bee6ac5 --- /dev/null +++ b/screenhandler/test/fuzztest/dscreenhandler_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/screenhandler/test/fuzztest/dscreenhandler_fuzzer/dscreen_handler_fuzzer.cpp b/screenhandler/test/fuzztest/dscreenhandler_fuzzer/dscreen_handler_fuzzer.cpp new file mode 100644 index 0000000000000000000000000000000000000000..99120d32819db24c715c5688fca9f1cd46627868 --- /dev/null +++ b/screenhandler/test/fuzztest/dscreenhandler_fuzzer/dscreen_handler_fuzzer.cpp @@ -0,0 +1,61 @@ +/* + * 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 "dscreen_handler_fuzzer.h" + +#include +#include +#include + +#include "dscreen_handler.h" +#include "device_type.h" +#include "ihardware_handler.h" +#include "local_hardware_manager.h" +#include "plugin_listener_impl.h" + +namespace OHOS { +namespace DistributedHardware { +void DscreenHandlerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + DHType dhType = DHType::DISPLAY; + std::shared_ptr listener = std::make_shared(dhType); + std::string dhId(reinterpret_cast(data), size); + std::string attr(reinterpret_cast(data), size); + + DScreenHandler::GetInstance().Initialize(); + DScreenHandler::GetInstance().Query(); + DScreenHandler::GetInstance().QueryExtraInfo(); + DScreenHandler::GetInstance().IsSupportPlugin(); + DScreenHandler::GetInstance().RegisterPluginListener(listener); + DScreenHandler::GetInstance().PluginHardware(dhId, attr); + DScreenHandler::GetInstance().UnPluginHardware(dhId); + DScreenHandler::GetInstance().UnRegisterPluginListener(); + DScreenHandler::GetInstance().QueryCodecInfo(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DscreenHandlerFuzzTest(data, size); + return 0; +} + diff --git a/screenhandler/test/fuzztest/dscreenhandler_fuzzer/dscreen_handler_fuzzer.h b/screenhandler/test/fuzztest/dscreenhandler_fuzzer/dscreen_handler_fuzzer.h new file mode 100644 index 0000000000000000000000000000000000000000..7ca6e15b62d240518f8d7e1d1d54df678a859034 --- /dev/null +++ b/screenhandler/test/fuzztest/dscreenhandler_fuzzer/dscreen_handler_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 DSCREEN_HANDLER_FUZZER_H +#define DSCREEN_HANDLER_FUZZER_H + +#define FUZZ_PROJECT_NAME "dscreen_handler_fuzzer" + +#endif \ No newline at end of file diff --git a/screenhandler/test/fuzztest/dscreenhandler_fuzzer/project.xml b/screenhandler/test/fuzztest/dscreenhandler_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..6e8ad2cfde8f8bda4beb6cabbe7efd8bc3c54eec --- /dev/null +++ b/screenhandler/test/fuzztest/dscreenhandler_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + +