From 20d6db40e84cdb2971b9ebcdd516138b1a66413e Mon Sep 17 00:00:00 2001 From: qinlong0101 Date: Tue, 26 Apr 2022 19:27:10 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9fuzz=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: qinlong0101 --- bundle.json | 1 - .../dscreen_sink_proxy_fuzzer.cpp | 8 ++ .../dscreen_source_proxy_fuzzer.cpp | 8 ++ services/screenservice/test/fuzztest/BUILD.gn | 18 ---- .../test/fuzztest/sinkservice_fuzzer/BUILD.gn | 94 ------------------- .../fuzztest/sinkservice_fuzzer/corpus/init | 14 --- .../fuzztest/sinkservice_fuzzer/project.xml | 25 ----- .../sink_service_fuzzer.cpp | 57 ----------- .../sinkservice_fuzzer/sink_service_fuzzer.h | 21 ----- 9 files changed, 16 insertions(+), 230 deletions(-) delete mode 100644 services/screenservice/test/fuzztest/BUILD.gn delete mode 100644 services/screenservice/test/fuzztest/sinkservice_fuzzer/BUILD.gn delete mode 100644 services/screenservice/test/fuzztest/sinkservice_fuzzer/corpus/init delete mode 100644 services/screenservice/test/fuzztest/sinkservice_fuzzer/project.xml delete mode 100644 services/screenservice/test/fuzztest/sinkservice_fuzzer/sink_service_fuzzer.cpp delete mode 100644 services/screenservice/test/fuzztest/sinkservice_fuzzer/sink_service_fuzzer.h diff --git a/bundle.json b/bundle.json index 3cedd469..b3f9f233 100644 --- a/bundle.json +++ b/bundle.json @@ -84,7 +84,6 @@ "//foundation/distributedhardware/distributedscreen/screenhandler/test/fuzztest:fuzztest", "//foundation/distributedhardware/distributedscreen/interfaces/innerkits/native_cpp/test/fuzztest:fuzztest", "//foundation/distributedhardware/distributedscreen/services/softbusadapter/test/fuzztest:fuzztest", - "//foundation/distributedhardware/distributedscreen/services/screenservice/test/fuzztest:fuzztest", "//foundation/distributedhardware/distributedscreen/services/screentransport/test/fuzztest:fuzztest" ] } 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 index 2852d900..1888eb30 100644 --- 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 @@ -40,7 +40,15 @@ void DscreenSinkProxyHandlerFuzzTest(const uint8_t* data, size_t 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); diff --git a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/dscreen_source_proxy_fuzzer.cpp b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/dscreen_source_proxy_fuzzer.cpp index 1a5b970f..32399053 100644 --- a/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/dscreen_source_proxy_fuzzer.cpp +++ b/interfaces/innerkits/native_cpp/test/fuzztest/dscreensourceproxy_fuzzer/dscreen_source_proxy_fuzzer.cpp @@ -51,7 +51,15 @@ void DscreenSourceProxyHandlerFuzzTest(const uint8_t* data, size_t size) sptr samgr = SystemAbilityManagerClient::GetInstance().GetSystemAbilityManager(); + if (samgr == nullptr) { + return; + } + sptr remoteObject = samgr->GetSystemAbility(DISTRIBUTED_HARDWARE_SCREEN_SOURCE_SA_ID); + if (remoteObject == nullptr) { + return; + } + std::shared_ptr dscreenSourceProxy = std::make_shared(remoteObject); dscreenSourceProxy->InitSource(params, callback); diff --git a/services/screenservice/test/fuzztest/BUILD.gn b/services/screenservice/test/fuzztest/BUILD.gn deleted file mode 100644 index a63f7a6f..00000000 --- a/services/screenservice/test/fuzztest/BUILD.gn +++ /dev/null @@ -1,18 +0,0 @@ -# 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 = [ "sinkservice_fuzzer:fuzztest" ] -} diff --git a/services/screenservice/test/fuzztest/sinkservice_fuzzer/BUILD.gn b/services/screenservice/test/fuzztest/sinkservice_fuzzer/BUILD.gn deleted file mode 100644 index 581a9fc5..00000000 --- a/services/screenservice/test/fuzztest/sinkservice_fuzzer/BUILD.gn +++ /dev/null @@ -1,94 +0,0 @@ -# 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("SinkServiceFuzzTest") { - module_out_path = "distributed_screen/sinkservice" - - fuzz_config_file = - "${services_path}/screenservice/test/fuzztest/sinkservice_fuzzer" - - include_dirs = [ - "//third_party/json/include", - "//utils/native/base/include", - "//utils/system/safwk/native/include", - "//foundation/graphic/standard/interfaces/innerkits/surface", - "${windowmanager_path}/interfaces/innerkits/dm", - "${fwk_common_path}/utils/include", - ] - - include_dirs += [ - "./dscreenservice/include", - "./screenregionmgr/include", - "${interfaces_path}/innerkits/native_cpp/screen_sink/include", - "${interfaces_path}/innerkits/native_cpp/screen_sink/include/callback", - "${interfaces_path}/innerkits/native_cpp/screen_source/include", - "${interfaces_path}/innerkits/native_cpp/screen_source/include/callback", - "${common_path}/include", - "${services_path}/common/utils/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/screentransport/screensinktrans/include", - "${services_path}/screentransport/screensinkprocessor/include", - "${services_path}/screentransport/screensinkprocessor/decoder/include", - "${services_path}/screenclient/include", - "${services_path}/screenservice/sinkservice/dscreenservice/include", - "${services_path}/screenservice/sinkservice/screenregionmgr/include", - ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "sink_service_fuzzer.cpp" ] - - deps = [ - "${common_path}:distributed_screen_utils", - "${services_path}/screenclient:distributed_screen_client", - "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans", - "${windowmanager_path}/dm:libdm", - "//foundation/distributedhardware/distributedscreen/services/screenservice/sinkservice:distributed_screen_sink", - "//foundation/graphic/standard/frameworks/surface:surface", - "//utils/native/base:utils", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SinkServiceFuzzTest\"", - "LOG_DOMAIN=0xD004100", - ] - - external_deps = [ - "hiviewdfx_hilog_native:libhilog", - "ipc:ipc_core", - "multimedia_media_standard:media_client", - "safwk:system_ability_fwk", - "samgr_standard:samgr_proxy", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SinkServiceFuzzTest" ] -} -############################################################################### diff --git a/services/screenservice/test/fuzztest/sinkservice_fuzzer/corpus/init b/services/screenservice/test/fuzztest/sinkservice_fuzzer/corpus/init deleted file mode 100644 index bc977bd9..00000000 --- a/services/screenservice/test/fuzztest/sinkservice_fuzzer/corpus/init +++ /dev/null @@ -1,14 +0,0 @@ -# Copyright (c) 2022 Huawei Device Co., Ltd. -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FUZZ \ No newline at end of file diff --git a/services/screenservice/test/fuzztest/sinkservice_fuzzer/project.xml b/services/screenservice/test/fuzztest/sinkservice_fuzzer/project.xml deleted file mode 100644 index 6e8ad2cf..00000000 --- a/services/screenservice/test/fuzztest/sinkservice_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/screenservice/test/fuzztest/sinkservice_fuzzer/sink_service_fuzzer.cpp b/services/screenservice/test/fuzztest/sinkservice_fuzzer/sink_service_fuzzer.cpp deleted file mode 100644 index f1988636..00000000 --- a/services/screenservice/test/fuzztest/sinkservice_fuzzer/sink_service_fuzzer.cpp +++ /dev/null @@ -1,57 +0,0 @@ -/* - * 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 "sink_service_fuzzer.h" - -#include -#include -#include - -#include "dscreen_sink_service.h" - -namespace OHOS { -namespace DistributedHardware { -void SinkServiceFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size <= sizeof(int32_t))) { - return; - } - - int32_t saId = *(reinterpret_cast(data)); - bool runOnCreate = true; - std::shared_ptr sinkService = std::make_shared(saId, runOnCreate); - 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); - - sinkService->DScreenNotify(devId, eventCode, eventContent); - sinkService->InitSink(params); - sinkService->SubscribeLocalHardware(dhId, param); - sinkService->UnsubscribeLocalHardware(dhId); - sinkService->ReleaseSink(); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SinkServiceFuzzTest(data, size); - return 0; -} \ No newline at end of file diff --git a/services/screenservice/test/fuzztest/sinkservice_fuzzer/sink_service_fuzzer.h b/services/screenservice/test/fuzztest/sinkservice_fuzzer/sink_service_fuzzer.h deleted file mode 100644 index 3f40dfac..00000000 --- a/services/screenservice/test/fuzztest/sinkservice_fuzzer/sink_service_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * 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 SINK_SERVICE_FUZZER_H -#define SINK_SERVICE_FUZZER_H - -#define FUZZ_PROJECT_NAME "sink_service_fuzzer" - -#endif \ No newline at end of file -- Gitee