From 2a64dd325304181cdc0537c95a4630046cc98a72 Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Wed, 13 Jul 2022 16:32:58 +0800 Subject: [PATCH] motify screen FuzzTest Signed-off-by: qinlong0101 --- .../native_cpp/test/fuzztest/BUILD.gn | 8 +++ .../handlerinitsink_fuzzer/BUILD.gn | 71 +++++++++++++++++++ .../handlerinitsink_fuzzer/corpus/init | 14 ++++ .../initsink_fuzzer.cpp | 45 ++++++++++++ .../handlerinitsink_fuzzer/initsink_fuzzer.h | 21 ++++++ .../handlerinitsink_fuzzer/project.xml | 25 +++++++ .../BUILD.gn | 71 +++++++++++++++++++ .../corpus/init | 14 ++++ .../onremotesinksvrdied_fuzzer.cpp | 59 +++++++++++++++ .../onremotesinksvrdied_fuzzer.h | 21 ++++++ .../project.xml | 25 +++++++ .../BUILD.gn | 71 +++++++++++++++++++ .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../subscribelocalhardware_fuzzer.cpp | 46 ++++++++++++ .../subscribelocalhardware_fuzzer.h | 21 ++++++ .../BUILD.gn | 71 +++++++++++++++++++ .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../unsubscribelocalhardware_fuzzer.cpp | 45 ++++++++++++ .../unsubscribelocalhardware_fuzzer.h | 21 ++++++ .../proxyinitsink_fuzzer/BUILD.gn | 71 +++++++++++++++++++ .../proxyinitsink_fuzzer/corpus/init | 14 ++++ .../proxyinitsink_fuzzer/initsink_fuzzer.cpp | 61 ++++++++++++++++ .../proxyinitsink_fuzzer/initsink_fuzzer.h | 21 ++++++ .../proxyinitsink_fuzzer/project.xml | 25 +++++++ .../BUILD.gn | 71 +++++++++++++++++++ .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../subscribelocalhardware_fuzzer.cpp | 62 ++++++++++++++++ .../subscribelocalhardware_fuzzer.h | 21 ++++++ .../BUILD.gn | 71 +++++++++++++++++++ .../corpus/init | 14 ++++ .../project.xml | 25 +++++++ .../unsubscribelocalhardware_fuzzer.cpp | 61 ++++++++++++++++ .../unsubscribelocalhardware_fuzzer.h | 21 ++++++ .../sinkproxydscreennotify_fuzzer/BUILD.gn | 71 +++++++++++++++++++ .../sinkproxydscreennotify_fuzzer/corpus/init | 14 ++++ .../sinkproxydscreennotify_fuzzer/project.xml | 25 +++++++ .../sinkproxydscreennotify_fuzzer.cpp | 63 ++++++++++++++++ .../sinkproxydscreennotify_fuzzer.h | 21 ++++++ 41 files changed, 1498 insertions(+) create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/BUILD.gn create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/corpus/init create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.cpp create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.h create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/project.xml create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/BUILD.gn create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/corpus/init create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/onremotesinksvrdied_fuzzer.cpp create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/onremotesinksvrdied_fuzzer.h create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/project.xml create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/BUILD.gn create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/corpus/init create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/project.xml create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.h create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/BUILD.gn create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/corpus/init create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/project.xml create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.h create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/BUILD.gn create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/corpus/init create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.cpp create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.h create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/project.xml create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/BUILD.gn create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/corpus/init create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/project.xml create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.h create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/BUILD.gn create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/corpus/init create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/project.xml create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.h create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/BUILD.gn create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/corpus/init create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/project.xml create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/sinkproxydscreennotify_fuzzer.cpp create mode 100644 interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/sinkproxydscreennotify_fuzzer.h diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn index a8229e8e..19e02b6a 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn +++ b/interfaces/innerkits/native_cpp/test/fuzztest/BUILD.gn @@ -15,6 +15,14 @@ group("fuzztest") { testonly = true deps = [ + "dscreen_sink_handler/handlerinitsink_fuzzer:fuzztest", + "dscreen_sink_handler/handleronremotesinksvrdied_fuzzer:fuzztest", + "dscreen_sink_handler/handlersubscribelocalhardware_fuzzer:fuzztest", + "dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer:fuzztest", + "dscreen_sink_proxy/proxyinitsink_fuzzer:fuzztest", + "dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer:fuzztest", + "dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer:fuzztest", + "dscreen_sink_proxy/sinkproxydscreennotify_fuzzer:fuzztest", "dscreen_source_handler/handlerconfigdistributedhardware_fuzzer:fuzztest", "dscreen_source_handler/handlerinitsource_fuzzer:fuzztest", "dscreen_source_handler/handleronremotesourcesvrdied_fuzzer:fuzztest", diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/BUILD.gn new file mode 100644 index 00000000..a5460553 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_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/distributed_screen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("HandlerInitSinkFuzzTest") { + module_out_path = "distributed_screen/dscreensinkhandler" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_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 = [ "initsink_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=\"HandlerInitSinkFuzzTest\"", + "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 = [ ":HandlerInitSinkFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_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/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.cpp new file mode 100644 index 00000000..b5acae69 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.cpp @@ -0,0 +1,45 @@ +/* + * 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 "initsink_fuzzer.h" + +#include +#include + +#include "dscreen_sink_handler.h" + +namespace OHOS { +namespace DistributedHardware { +void InitSinkFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string params(reinterpret_cast(data), size); + + DScreenSinkHandler::GetInstance().InitSink(params); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::InitSinkFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_fuzzer.h new file mode 100644 index 00000000..f3489275 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/initsink_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 INITSINK_FUZZER_H +#define INITSINK_FUZZER_H + +#define FUZZ_PROJECT_NAME "initsink_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerinitsink_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/BUILD.gn new file mode 100644 index 00000000..8eb4bbd7 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_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/distributed_screen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("HandlerOnRemoteSinkSvrDiedFuzzTest") { + module_out_path = "distributed_screen/dscreensinkhandler" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_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 = [ "onremotesinksvrdied_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=\"HandlerOnRemoteSinkSvrDiedFuzzTest\"", + "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 = [ ":HandlerOnRemoteSinkSvrDiedFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_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/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/onremotesinksvrdied_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/onremotesinksvrdied_fuzzer.cpp new file mode 100644 index 00000000..52a91ac0 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/onremotesinksvrdied_fuzzer.cpp @@ -0,0 +1,59 @@ +/* + * 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 "onremotesinksvrdied_fuzzer.h" + +#include +#include + +#include "dscreen_sink_handler.h" +#include "if_system_ability_manager.h" +#include "iservice_registry.h" + +namespace OHOS { +namespace DistributedHardware { +void OnRemoteSinkSvrDiedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + int32_t saId = *(reinterpret_cast(data)); + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr != nullptr) { + return; + } + + sptr remoteObject = samgr->GetSystemAbility(saId); + if (remoteObject == nullptr) { + return; + } + wptr remote(remoteObject); + + 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::OnRemoteSinkSvrDiedFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/onremotesinksvrdied_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/onremotesinksvrdied_fuzzer.h new file mode 100644 index 00000000..c8955a0e --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/onremotesinksvrdied_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 ONREMOTESINKSVRDIED_FUZZER_H +#define ONREMOTESINKSVRDIED_FUZZER_H + +#define FUZZ_PROJECT_NAME "onremotesinksvrdied_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handleronremotesinksvrdied_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/BUILD.gn new file mode 100644 index 00000000..b3bf3bdb --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_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/distributed_screen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("HandlerSubscribeLocalHardwareFuzzTest") { + module_out_path = "distributed_screen/dscreensinkhandler" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_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 = [ "subscribelocalhardware_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=\"HandlerSubscribeLocalHardwareFuzzTest\"", + "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 = [ ":HandlerSubscribeLocalHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_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/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp new file mode 100644 index 00000000..e6b49992 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp @@ -0,0 +1,46 @@ +/* + * 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 "subscribelocalhardware_fuzzer.h" + +#include +#include + +#include "dscreen_sink_handler.h" + +namespace OHOS { +namespace DistributedHardware { +void SubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string dhId(reinterpret_cast(data), size); + std::string param(reinterpret_cast(data), size); + + DScreenSinkHandler::GetInstance().SubscribeLocalHardware(dhId, param); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SubscribeLocalHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.h new file mode 100644 index 00000000..e8160cba --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlersubscribelocalhardware_fuzzer/subscribelocalhardware_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 SUBSCRIBELOCALHARDWARE_FUZZER_H +#define SUBSCRIBELOCALHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "subscribelocalhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/BUILD.gn new file mode 100644 index 00000000..53ff4b18 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_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/distributed_screen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("HandlerUnsubscribeLocalHardwareFuzzTest") { + module_out_path = "distributed_screen/dscreensinkhandler" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_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 = [ "unsubscribelocalhardware_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=\"HandlerUnsubscribeLocalHardwareFuzzTest\"", + "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 = [ ":HandlerUnsubscribeLocalHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_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/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp new file mode 100644 index 00000000..cdeecb14 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp @@ -0,0 +1,45 @@ +/* + * 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 "unsubscribelocalhardware_fuzzer.h" + +#include +#include + +#include "dscreen_sink_handler.h" + +namespace OHOS { +namespace DistributedHardware { +void UnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= 0)) { + return; + } + + std::string dhId(reinterpret_cast(data), size); + + DScreenSinkHandler::GetInstance().UnsubscribeLocalHardware(dhId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::UnsubscribeLocalHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.h new file mode 100644 index 00000000..45c989e5 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_handler/handlerunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_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 UNSUBSCRIBELOCALHARDWARE_FUZZER_H +#define UNSUBSCRIBELOCALHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "unsubscribelocalhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/BUILD.gn new file mode 100644 index 00000000..a32b857f --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_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/distributed_screen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ProxyInitSinkFuzzTest") { + module_out_path = "distributed_screen/dscreensinkproxy" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_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 = [ "initsink_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=\"ProxyInitSinkFuzzTest\"", + "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 = [ ":ProxyInitSinkFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_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/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.cpp new file mode 100644 index 00000000..a4890048 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_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 "initsink_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 InitSinkFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= sizeof(int32_t))) { + return; + } + + std::string params(reinterpret_cast(data), size); + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + return; + } + + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID); + if (remoteObject == nullptr) { + return; + } + + std::shared_ptr dscreenSinkProxy = std::make_shared(remoteObject); + + dscreenSinkProxy->InitSink(params); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::InitSinkFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_fuzzer.h new file mode 100644 index 00000000..f3489275 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/initsink_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 INITSINK_FUZZER_H +#define INITSINK_FUZZER_H + +#define FUZZ_PROJECT_NAME "initsink_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyinitsink_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/BUILD.gn new file mode 100644 index 00000000..bfa6ff3a --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_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/distributed_screen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ProxySubscribeLocalHardwareFuzzTest") { + module_out_path = "distributed_screen/dscreensinkproxy" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_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 = [ "subscribelocalhardware_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=\"ProxySubscribeLocalHardwareFuzzTest\"", + "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 = [ ":ProxySubscribeLocalHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_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/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.cpp new file mode 100644 index 00000000..c3db6e4c --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/subscribelocalhardware_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 "subscribelocalhardware_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 SubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= sizeof(int32_t))) { + return; + } + + std::string dhId(reinterpret_cast(data), size); + std::string param(reinterpret_cast(data), size); + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + return; + } + + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID); + if (remoteObject == nullptr) { + return; + } + + std::shared_ptr dscreenSinkProxy = std::make_shared(remoteObject); + + dscreenSinkProxy->SubscribeLocalHardware(dhId, param); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::SubscribeLocalHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/subscribelocalhardware_fuzzer.h new file mode 100644 index 00000000..e8160cba --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxysubscribelocalhardware_fuzzer/subscribelocalhardware_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 SUBSCRIBELOCALHARDWARE_FUZZER_H +#define SUBSCRIBELOCALHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "subscribelocalhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/BUILD.gn new file mode 100644 index 00000000..271f7082 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_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/distributed_screen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ProxyUnsubscribeLocalHardwareFuzzTest") { + module_out_path = "distributed_screen/dscreensinkproxy" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_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 = [ "unsubscribelocalhardware_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=\"ProxyUnsubscribeLocalHardwareFuzzTest\"", + "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 = [ ":ProxyUnsubscribeLocalHardwareFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_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/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.cpp new file mode 100644 index 00000000..e98d94ee --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_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 "unsubscribelocalhardware_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 UnsubscribeLocalHardwareFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= sizeof(int32_t))) { + return; + } + + std::string dhId(reinterpret_cast(data), size); + + sptr samgr = + SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + return; + } + + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID); + if (remoteObject == nullptr) { + return; + } + + std::shared_ptr dscreenSinkProxy = std::make_shared(remoteObject); + + dscreenSinkProxy->UnsubscribeLocalHardware(dhId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::UnsubscribeLocalHardwareFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_fuzzer.h new file mode 100644 index 00000000..45c989e5 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/proxyunsubscribelocalhardware_fuzzer/unsubscribelocalhardware_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 UNSUBSCRIBELOCALHARDWARE_FUZZER_H +#define UNSUBSCRIBELOCALHARDWARE_FUZZER_H + +#define FUZZ_PROJECT_NAME "unsubscribelocalhardware_fuzzer" + +#endif \ No newline at end of file diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/BUILD.gn b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/BUILD.gn new file mode 100644 index 00000000..866c5988 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_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/distributed_screen/distributedscreen.gni") + +##############################fuzztest########################################## +ohos_fuzztest("SinkProxyDScreenNotifyFuzzTest") { + module_out_path = "distributed_screen/dscreensinkproxy" + + fuzz_config_file = "${interfaces_path}/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_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 = [ "sinkproxydscreennotify_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=\"SinkProxyDScreenNotifyFuzzTest\"", + "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 = [ ":SinkProxyDScreenNotifyFuzzTest" ] +} +############################################################################### diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/corpus/init b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/corpus/init new file mode 100644 index 00000000..bc977bd9 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_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/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/project.xml b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/project.xml new file mode 100644 index 00000000..6e8ad2cf --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/sinkproxydscreennotify_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/sinkproxydscreennotify_fuzzer.cpp new file mode 100644 index 00000000..9d3ecdb3 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/sinkproxydscreennotify_fuzzer.cpp @@ -0,0 +1,63 @@ +/* + * 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 "sinkproxydscreennotify_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 DScreenNotifyFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size <= sizeof(int32_t))) { + return; + } + + 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(); + if (samgr == nullptr) { + return; + } + + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SINK_SA_ID); + if (remoteObject == nullptr) { + return; + } + + std::shared_ptr dscreenSinkProxy = std::make_shared(remoteObject); + + dscreenSinkProxy->DScreenNotify(devId, eventCode, eventContent); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DScreenNotifyFuzzTest(data, size); + return 0; +} + diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/sinkproxydscreennotify_fuzzer.h b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/sinkproxydscreennotify_fuzzer.h new file mode 100644 index 00000000..43995b97 --- /dev/null +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreen_sink_proxy/sinkproxydscreennotify_fuzzer/sinkproxydscreennotify_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 SINKPROXYDSCREENNOTIFY_FUZZER_H +#define SINKPROXYDSCREENNOTIFY_FUZZER_H + +#define FUZZ_PROJECT_NAME "sinkproxydscreennotify_fuzzer" + +#endif \ No newline at end of file -- Gitee