From 29a2a20f02618ac89ae93c93d2fa56aa3e1dde18 Mon Sep 17 00:00:00 2001 From: pwx1285814 Date: Mon, 5 Aug 2024 19:46:38 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A1=A5=E5=85=85fuzz=E7=94=A8=E4=BE=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: pwx1285814 --- services/screenservice/test/fuzztest/BUILD.gn | 2 +- .../BUILD.gn | 10 +- .../corpus/init | 0 .../dscreenmanager_fuzzer.cpp | 170 ++++++++++++++++++ .../dscreenmanager_fuzzer.h} | 2 +- .../project.xml | 0 .../onchange_fuzzer/onchange_fuzzer.cpp | 49 ----- .../softbusadapter/test/fuzztest/BUILD.gn | 9 +- .../softbusadapter_fuzzer.cpp | 144 ++++++++++++++- .../softbusadapter_fuzzer.h | 16 ++ .../softbusonbytesreceived_fuzzer/BUILD.gn | 63 ------- .../softbusonbytesreceived_fuzzer/corpus/init | 16 -- .../softbusonbytesreceived_fuzzer/project.xml | 25 --- .../softbusonbytesreceived_fuzzer.cpp | 51 ------ .../softbusonbytesreceived_fuzzer.h | 21 --- .../softbusonmessagereceived_fuzzer/BUILD.gn | 63 ------- .../corpus/init | 16 -- .../project.xml | 25 --- .../softbusonmessagereceived_fuzzer.cpp | 51 ------ .../softbusonmessagereceived_fuzzer.h | 21 --- .../softbusonsessionclosed_fuzzer/BUILD.gn | 63 ------- .../softbusonsessionclosed_fuzzer/corpus/init | 16 -- .../softbusonsessionclosed_fuzzer/project.xml | 25 --- .../softbusonsessionclosed_fuzzer.cpp | 50 ------ .../softbusonsessionclosed_fuzzer.h | 21 --- .../softbusonsessionopened_fuzzer/BUILD.gn | 63 ------- .../softbusonsessionopened_fuzzer/corpus/init | 16 -- .../softbusonsessionopened_fuzzer/project.xml | 25 --- .../softbusonsessionopened_fuzzer.cpp | 60 ------- .../softbusonsessionopened_fuzzer.h | 21 --- .../softbusonstreamreceived_fuzzer/BUILD.gn | 63 ------- .../corpus/init | 16 -- .../project.xml | 25 --- .../softbusonstreamreceived_fuzzer.cpp | 50 ------ .../softbusonstreamreceived_fuzzer.h | 21 --- 35 files changed, 337 insertions(+), 952 deletions(-) rename services/screenservice/test/fuzztest/sourceservice/dscreenmgr/{onchange_fuzzer => dscreenmanager_fuzzer}/BUILD.gn (91%) rename services/screenservice/test/fuzztest/sourceservice/dscreenmgr/{onchange_fuzzer => dscreenmanager_fuzzer}/corpus/init (100%) create mode 100644 services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp rename services/screenservice/test/fuzztest/sourceservice/dscreenmgr/{onchange_fuzzer/onchange_fuzzer.h => dscreenmanager_fuzzer/dscreenmanager_fuzzer.h} (93%) rename services/screenservice/test/fuzztest/sourceservice/dscreenmgr/{onchange_fuzzer => dscreenmanager_fuzzer}/project.xml (100%) delete mode 100644 services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h delete mode 100644 services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.h delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp delete mode 100644 services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h diff --git a/services/screenservice/test/fuzztest/BUILD.gn b/services/screenservice/test/fuzztest/BUILD.gn index 4d55ed50..a4905fb7 100644 --- a/services/screenservice/test/fuzztest/BUILD.gn +++ b/services/screenservice/test/fuzztest/BUILD.gn @@ -16,7 +16,7 @@ group("fuzztest") { deps = [ "sinkservice/dscreenservice/dscreensinkstub_fuzzer:fuzztest", - "sourceservice/dscreenmgr/onchange_fuzzer:fuzztest", + "sourceservice/dscreenmgr/dscreenmanager_fuzzer:fuzztest", "sourceservice/dscreenservice/dscreensourcecallbackproxy_fuzzer:fuzztest", "sourceservice/dscreenservice/dscreensourceservice_fuzzer:fuzztest", "sourceservice/dscreenservice/dscreensourcestub_fuzzer:fuzztest", diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/BUILD.gn b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/BUILD.gn similarity index 91% rename from services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/BUILD.gn rename to services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/BUILD.gn index be9d7eaa..885e1a59 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/BUILD.gn +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/BUILD.gn @@ -17,10 +17,10 @@ import("//build/test.gni") import("../../../../../../../distributedscreen.gni") ##############################fuzztest########################################## -ohos_fuzztest("OnChangeFuzzTest") { +ohos_fuzztest("DScreenManagerFuzzTest") { module_out_path = "${fuzz_test_path}/sourceservice" - fuzz_config_file = "${services_path}/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer" + fuzz_config_file = "${services_path}/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer" include_dirs = [ "./dscreenservice/include/callback", @@ -37,7 +37,7 @@ ohos_fuzztest("OnChangeFuzzTest") { configs = [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - sources = [ "onchange_fuzzer.cpp" ] + sources = [ "dscreenmanager_fuzzer.cpp" ] deps = [ "${services_path}/screenservice/sourceservice:distributed_screen_source", @@ -45,7 +45,7 @@ ohos_fuzztest("OnChangeFuzzTest") { defines = [ "HI_LOG_ENABLE", - "DH_LOG_TAG=\"OnChangeFuzzTest\"", + "DH_LOG_TAG=\"DScreenManagerFuzzTest\"", "LOG_DOMAIN=0xD004140", ] @@ -64,6 +64,6 @@ ohos_fuzztest("OnChangeFuzzTest") { ############################################################################### group("fuzztest") { testonly = true - deps = [ ":OnChangeFuzzTest" ] + deps = [ ":DScreenManagerFuzzTest" ] } ############################################################################### diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/corpus/init b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/corpus/init similarity index 100% rename from services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/corpus/init rename to services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/corpus/init diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp new file mode 100644 index 00000000..eab2ca77 --- /dev/null +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.cpp @@ -0,0 +1,170 @@ +/* + * Copyright (c) 2023-2024 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 "dscreenmanager_fuzzer.h" + +#include +#include + +#include "1.0/include/dscreen_manager.h" + +namespace OHOS { +namespace DistributedHardware { +namespace V1_0 { +void OnChangeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint64_t))) { + return; + } + std::vector screenIds; + uint64_t screenIdOne = *(reinterpret_cast(data)); + screenIds.emplace_back(screenIdOne); + Rosen::ScreenGroupChangeEvent event = Rosen::ScreenGroupChangeEvent::ADD_TO_GROUP; + DScreenGroupListener dScreenGroupListener; + dScreenGroupListener.OnChange(screenIds, event); +} + +void HandleScreenChangeFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t))) { + return; + } + + uint32_t eventValue = *(reinterpret_cast(data)) % 3; + if ((eventValue != static_cast(Rosen::ScreenGroupChangeEvent::ADD_TO_GROUP)) || + (eventValue != static_cast(Rosen::ScreenGroupChangeEvent::ADD_TO_GROUP)) || + (eventValue != static_cast(Rosen::ScreenGroupChangeEvent::ADD_TO_GROUP))) { + return; + } + + std::shared_ptr dScreenCallback = std::make_shared(); + std::shared_ptr dScreen = std::make_shared("devId000", "dhId000", dScreenCallback); + Rosen::ScreenGroupChangeEvent event = static_cast(eventValue); + + std::shared_ptr dscreenManager = std::make_shared(); + dscreenManager->HandleScreenChange(dScreen, event); +} + +void AddToGroupFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint64_t))) { + return; + } + + uint64_t screenId = *(reinterpret_cast(data)); + std::shared_ptr dScreenCallback = std::make_shared(); + std::shared_ptr dScreen = std::make_shared("devId000", "dhId000", dScreenCallback); + + std::shared_ptr dscreenManager = std::make_shared(); + dscreenManager->AddToGroup(dScreen, screenId); + dscreenManager->RemoveFromGroup(dScreen, screenId); +} + +void DScreenCallbackOnRegResultFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + + std::string reqId(reinterpret_cast(data), size); + std::string screenId(reinterpret_cast(data), size); + int32_t status = *(reinterpret_cast(data)); + std::string dataStr(reinterpret_cast(data), size); + + std::shared_ptr dScreenCallback = std::make_shared(); + std::shared_ptr dScreen = std::make_shared("devId000", "dhId000", dScreenCallback); + dScreenCallback->OnRegResult(dScreen, screenId, status, dataStr); + dScreenCallback->OnUnregResult(dScreen, screenId, status, dataStr); +} + +void DScreenManagerOnUnregResultFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + + std::string reqId(reinterpret_cast(data), size); + int32_t status = *(reinterpret_cast(data)); + std::string dataStr(reinterpret_cast(data), size); + + std::shared_ptr dScreenCallback = std::make_shared(); + std::shared_ptr dScreen = std::make_shared("devId000", "dhId000", dScreenCallback); + std::shared_ptr dscreenManager = std::make_shared(); + dscreenManager->OnRegResult(dScreen, reqId, status, dataStr); + dscreenManager->OnUnregResult(dScreen, reqId, status, dataStr); +} + +void EnableDistributedScreenFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + std::string str(reinterpret_cast(data), size); + std::string devId(reinterpret_cast(data), size); + std::string dhId(reinterpret_cast(data), size); + std::string reqId(reinterpret_cast(data), size); + EnableParam param = {str, str, str, str}; + + std::shared_ptr dscreenManager = std::make_shared(); + dscreenManager->EnableDistributedScreen(devId, dhId, param, reqId); + dscreenManager->DisableDistributedScreen(devId, dhId, reqId); +} + +void NotifyRemoteScreenServiceFuzzTest(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); + + std::shared_ptr dscreenManager = std::make_shared(); + dscreenManager->NotifyRemoteScreenService(devId, eventCode, eventContent); +} + +void HandleNotifySetUpResultFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + + std::string remoteDevId(reinterpret_cast(data), size); + std::string eventContent(reinterpret_cast(data), size); + + std::shared_ptr dscreenManager = std::make_shared(); + dscreenManager->HandleNotifySetUpResult(remoteDevId, eventContent); +} + +} // namespace V1_0 +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::V1_0::OnChangeFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::HandleScreenChangeFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::AddToGroupFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::DScreenCallbackOnRegResultFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::DScreenManagerOnUnregResultFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::EnableDistributedScreenFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::NotifyRemoteScreenServiceFuzzTest(data, size); + OHOS::DistributedHardware::V1_0::HandleNotifySetUpResultFuzzTest(data, size); + return 0; +} diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.h b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.h similarity index 93% rename from services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.h rename to services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.h index 26a3775e..91d433d3 100644 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.h +++ b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/dscreenmanager_fuzzer.h @@ -16,6 +16,6 @@ #ifndef ONCHANGE_FUZZER_H #define ONCHANGE_FUZZER_H -#define FUZZ_PROJECT_NAME "onchange_fuzzer" +#define FUZZ_PROJECT_NAME "dscreenmanager_fuzzer" #endif \ No newline at end of file diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/project.xml b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/project.xml similarity index 100% rename from services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/project.xml rename to services/screenservice/test/fuzztest/sourceservice/dscreenmgr/dscreenmanager_fuzzer/project.xml diff --git a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.cpp b/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.cpp deleted file mode 100644 index 44c0b0d8..00000000 --- a/services/screenservice/test/fuzztest/sourceservice/dscreenmgr/onchange_fuzzer/onchange_fuzzer.cpp +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2023-2024 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 "onchange_fuzzer.h" - -#include -#include - -#include "1.0/include/dscreen_manager.h" - -namespace OHOS { -namespace DistributedHardware { -namespace V1_0 { -void OnChangeFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(uint64_t))) { - return; - } - std::vector screenIds; - uint64_t screenIdOne = *(reinterpret_cast(data)); - screenIds.emplace_back(screenIdOne); - Rosen::ScreenGroupChangeEvent event = Rosen::ScreenGroupChangeEvent::ADD_TO_GROUP; - DScreenGroupListener dScreenGroupListener; - dScreenGroupListener.OnChange(screenIds, event); -} -} // namespace V1_0 -} // namespace DistributedHardware -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::V1_0::OnChangeFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/BUILD.gn b/services/softbusadapter/test/fuzztest/BUILD.gn index 5798ca82..d04b76d9 100644 --- a/services/softbusadapter/test/fuzztest/BUILD.gn +++ b/services/softbusadapter/test/fuzztest/BUILD.gn @@ -14,12 +14,5 @@ group("fuzztest") { testonly = true - deps = [ - "softbusadapter_fuzzer:fuzztest", - "softbusonbytesreceived_fuzzer:fuzztest", - "softbusonmessagereceived_fuzzer:fuzztest", - "softbusonsessionclosed_fuzzer:fuzztest", - "softbusonsessionopened_fuzzer:fuzztest", - "softbusonstreamreceived_fuzzer:fuzztest", - ] + deps = [ "softbusadapter_fuzzer:fuzztest" ] } diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp index 50223e1c..53a500bc 100644 --- a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp @@ -19,9 +19,9 @@ #include "dscreen_errcode.h" #include "dscreen_util.h" #include "isoftbus_listener.h" +#include "softbus_adapter.h" #include "softbus_bus_center.h" #include "softbus_common.h" -#include "softbus_adapter.h" namespace OHOS { namespace DistributedHardware { @@ -62,6 +62,138 @@ void SoftbusAdapterFuzzTest(const uint8_t* data, size_t size) adapter->SendSoftbusBytes(sessionId, adapterData, dataLen1); adapter->CloseSoftbusSession(sessionId); } + +void SoftbusOnBytesReceivedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + void *adapterData = nullptr; + uint32_t dataLen = *(reinterpret_cast(data)); + std::shared_ptr adapter = std::make_shared(); + adapter->OnBytesReceived(sessionId, adapterData, dataLen); +} + +void SoftbusOnMessageReceivedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + void *adapterData = nullptr; + unsigned int dataLen = *(reinterpret_cast(data)); + std::shared_ptr adapter = std::make_shared(); + adapter->OnMessageReceived(sessionId, adapterData, dataLen); +} + +void SoftbusOnSessionClosedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + std::shared_ptr adapter = std::make_shared(); + ShutdownReason reason = SHUTDOWN_REASON_UNKNOWN; + adapter->OnSoftbusSessionClosed(sessionId, reason); +} + +void SoftbusOnSessionOpenedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + PeerSocketInfo peerSocketInfo = { + .name = const_cast(PEER_SESSION_NAME.c_str()), + .networkId = const_cast(REMOTE_DEV_ID.c_str()), + .pkgName = const_cast(DSCREEN_PKG_NAME_TEST.c_str()), + .dataType = DATA_TYPE_BYTES + }; + std::shared_ptr adapter = std::make_shared(); + adapter->OnSoftbusSessionOpened(sessionId, peerSocketInfo); +} + +void SoftbusOnStreamReceivedFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < (sizeof(int32_t)))) { + return; + } + int32_t sessionId = *(reinterpret_cast(data)); + StreamData *stream = nullptr; + StreamData *ext = nullptr; + StreamFrameInfo *info = nullptr; + std::shared_ptr adapter = std::make_shared(); + adapter->OnStreamReceived(sessionId, stream, ext, info); +} + +void SoftbusRegisterSoftbusListenerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::shared_ptr listener = std::make_shared(); + std::string sessionName(reinterpret_cast(data), size); + std::string peerDevId(reinterpret_cast(data), size); + + std::shared_ptr softbusAdapter = std::make_shared(); + (void)softbusAdapter->RegisterSoftbusListener(listener, sessionName, peerDevId); + (void)softbusAdapter->UnRegisterSoftbusListener(sessionName, peerDevId); +} + +void SoftbusUnRegisterSoftbusListenerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string sessionName(reinterpret_cast(data), size); + std::string peerDevId(reinterpret_cast(data), size); + + std::shared_ptr softbusAdapter = std::make_shared(); + (void)softbusAdapter->UnRegisterSoftbusListener(sessionName, peerDevId); +} + +void SoftbusCreateSoftbusSessionServerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string pkgName(reinterpret_cast(data), size); + std::string sessionName(reinterpret_cast(data), size); + std::string peerDevId(reinterpret_cast(data), size); + + std::shared_ptr softbusAdapter = std::make_shared(); + (void)softbusAdapter->CreateSoftbusSessionServer(pkgName, sessionName, peerDevId); + (void)softbusAdapter->RemoveSoftbusSessionServer(pkgName, sessionName, peerDevId); +} + +void SoftbusRemoveSoftbusSessionServerFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string pkgName(reinterpret_cast(data), size); + std::string sessionName(reinterpret_cast(data), size); + std::string peerDevId(reinterpret_cast(data), size); + + std::shared_ptr softbusAdapter = std::make_shared(); + (void)softbusAdapter->RemoveSoftbusSessionServer(pkgName, sessionName, peerDevId); +} + +void SoftbusOpenSoftbusSessionFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + std::string mySessionName(reinterpret_cast(data), size); + std::string peerSessionName(reinterpret_cast(data), size); + std::string peerDevId(reinterpret_cast(data), size); + + std::shared_ptr softbusAdapter = std::make_shared(); + int32_t socketId = softbusAdapter->OpenSoftbusSession(mySessionName, peerSessionName, peerDevId); + (void)softbusAdapter->CloseSoftbusSession(socketId); +} + } // namespace DistributedHardware } // namespace OHOS @@ -70,5 +202,15 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::SoftbusAdapterFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusOnBytesReceivedFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusOnMessageReceivedFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusOnSessionClosedFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusOnSessionOpenedFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusOnStreamReceivedFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusRegisterSoftbusListenerFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusUnRegisterSoftbusListenerFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusCreateSoftbusSessionServerFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusRemoveSoftbusSessionServerFuzzTest(data, size); + OHOS::DistributedHardware::SoftbusOpenSoftbusSessionFuzzTest(data, size); return 0; } diff --git a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h index d6ae1c1c..4e1bde8c 100644 --- a/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h +++ b/services/softbusadapter/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.h @@ -18,4 +18,20 @@ #define FUZZ_PROJECT_NAME "softbusadapter_fuzzer" +#include "isoftbus_listener.h" + +namespace OHOS { +namespace DistributedHardware { +class MockSoftbusListener : public ISoftbusListener { +public: + MockSoftbusListener() = default; + ~MockSoftbusListener() = default; + void OnSessionOpened(int32_t sessionId, PeerSocketInfo info) override {} + void OnSessionClosed(int32_t sessionId, ShutdownReason reason) override {} + void OnBytesReceived(int32_t sessionId, const void *data, uint32_t dataLen) override {} + void OnStreamReceived(int32_t sessionId, const StreamData *data, const StreamData *ext, + const StreamFrameInfo *param) override {} +}; +} // namespace DistributedHardware +} // namespace OHOS #endif diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn deleted file mode 100644 index 36b525b0..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/BUILD.gn +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2023-2024 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("../../../../../distributedscreen.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnBytesReceivedFuzzTest") { - module_out_path = "${fuzz_test_path}/softbusadapter" - fuzz_config_file = "${services_path}/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer" - - configs = - [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - - sources = [ "softbusonbytesreceived_fuzzer.cpp" ] - - include_dirs = [ - "${common_path}/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/common/utils/include", - "${services_path}/screentransport/screensourcetrans/include", - "${services_path}/screentransport/screendatachannel/include", - "${services_path}/screentransport/screensourceprocessor/include", - "${services_path}/screentransport/screensourceprocessor/encoder/include", - "${services_path}/softbusadapter/include", - ] - - deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributed_av_receiver", - "distributed_hardware_fwk:libdhfwk_sdk", - "dsoftbus:softbus_client", - "hilog:libhilog", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnBytesReceivedFuzzTest\"", - "LOG_DOMAIN=0xD004140", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnBytesReceivedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2023 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/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp deleted file mode 100644 index 5dde7dd2..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2023-2024 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 "softbusonbytesreceived_fuzzer.h" - -#include - -#include "dscreen_constants.h" -#include "dscreen_errcode.h" -#include "dscreen_util.h" -#include "isoftbus_listener.h" -#include "softbus_bus_center.h" -#include "softbus_common.h" -#include "softbus_adapter.h" - -namespace OHOS { -namespace DistributedHardware { -void SoftbusOnBytesReceivedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - int32_t sessionId = *(reinterpret_cast(data)); - void *adapterData = nullptr; - uint32_t dataLen = *(reinterpret_cast(data)); - std::shared_ptr adapter = std::make_shared(); - adapter->OnBytesReceived(sessionId, adapterData, dataLen); -} -} // namespace DistributedHardware -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SoftbusOnBytesReceivedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h deleted file mode 100644 index 245aaab3..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonbytesreceived_fuzzer/softbusonbytesreceived_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 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 SOFTBUSONBYTESRECEIVED_FUZZER_H -#define SOFTBUSONBYTESRECEIVED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonbytesreceived_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/BUILD.gn deleted file mode 100644 index f6dbb0ba..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/BUILD.gn +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2023-2024 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("../../../../../distributedscreen.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnMessageReceivedFuzzTest") { - module_out_path = "${fuzz_test_path}/softbusadapter" - fuzz_config_file = "${services_path}/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer" - - configs = - [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - - sources = [ "softbusonmessagereceived_fuzzer.cpp" ] - - include_dirs = [ - "${common_path}/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/common/utils/include", - "${services_path}/screentransport/screensourcetrans/include", - "${services_path}/screentransport/screendatachannel/include", - "${services_path}/screentransport/screensourceprocessor/include", - "${services_path}/screentransport/screensourceprocessor/encoder/include", - "${services_path}/softbusadapter/include", - ] - - deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributed_av_receiver", - "distributed_hardware_fwk:libdhfwk_sdk", - "dsoftbus:softbus_client", - "hilog:libhilog", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnMessageReceivedFuzzTest\"", - "LOG_DOMAIN=0xD004140", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnMessageReceivedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2023 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/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.cpp deleted file mode 100644 index ed354701..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.cpp +++ /dev/null @@ -1,51 +0,0 @@ -/* - * Copyright (c) 2023-2024 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 "softbusonmessagereceived_fuzzer.h" - -#include - -#include "dscreen_constants.h" -#include "dscreen_errcode.h" -#include "dscreen_util.h" -#include "isoftbus_listener.h" -#include "softbus_bus_center.h" -#include "softbus_common.h" -#include "softbus_adapter.h" - -namespace OHOS { -namespace DistributedHardware { -void SoftbusOnMessageReceivedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - int32_t sessionId = *(reinterpret_cast(data)); - void *adapterData = nullptr; - unsigned int dataLen = *(reinterpret_cast(data)); - std::shared_ptr adapter = std::make_shared(); - adapter->OnMessageReceived(sessionId, adapterData, dataLen); -} -} // namespace DistributedHardware -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SoftbusOnMessageReceivedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.h deleted file mode 100644 index 1fe5ddd5..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonmessagereceived_fuzzer/softbusonmessagereceived_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 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 SOFTBUSONMESSAGESECEIVED_FUZZER_H -#define SOFTBUSONMESSAGESECEIVED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonmessagereceived_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn deleted file mode 100644 index bb63ac68..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/BUILD.gn +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2023-2024 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("../../../../../distributedscreen.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnSessionClosedFuzzTest") { - module_out_path = "${fuzz_test_path}/softbusadapter" - fuzz_config_file = "${services_path}/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer" - - configs = - [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - - sources = [ "softbusonsessionclosed_fuzzer.cpp" ] - - include_dirs = [ - "${common_path}/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/common/utils/include", - "${services_path}/screentransport/screensourcetrans/include", - "${services_path}/screentransport/screendatachannel/include", - "${services_path}/screentransport/screensourceprocessor/include", - "${services_path}/screentransport/screensourceprocessor/encoder/include", - "${services_path}/softbusadapter/include", - ] - - deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributed_av_receiver", - "distributed_hardware_fwk:libdhfwk_sdk", - "dsoftbus:softbus_client", - "hilog:libhilog", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnSessionClosedFuzzTest\"", - "LOG_DOMAIN=0xD004140", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnSessionClosedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2023 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/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp deleted file mode 100644 index ede42c68..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2023-2024 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 "softbusonsessionclosed_fuzzer.h" - -#include - -#include "dscreen_constants.h" -#include "dscreen_errcode.h" -#include "dscreen_util.h" -#include "isoftbus_listener.h" -#include "softbus_bus_center.h" -#include "softbus_common.h" -#include "softbus_adapter.h" - -namespace OHOS { -namespace DistributedHardware { -void SoftbusOnSessionClosedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - int32_t sessionId = *(reinterpret_cast(data)); - std::shared_ptr adapter = std::make_shared(); - ShutdownReason reason = SHUTDOWN_REASON_UNKNOWN; - adapter->OnSoftbusSessionClosed(sessionId, reason); -} -} // namespace DistributedHardware -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SoftbusOnSessionClosedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h deleted file mode 100644 index 8641aaaa..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionclosed_fuzzer/softbusonsessionclosed_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 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 SOFTBUSONSESSIONCLOSED_FUZZER_H -#define SOFTBUSONSESSIONCLOSED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonsessionclosed_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn deleted file mode 100644 index 78ab9843..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/BUILD.gn +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2023-2024 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("../../../../../distributedscreen.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnSessionOpenedFuzzTest") { - module_out_path = "${fuzz_test_path}/softbusadapter" - fuzz_config_file = "${services_path}/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer" - - configs = - [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - - sources = [ "softbusonsessionopened_fuzzer.cpp" ] - - include_dirs = [ - "${common_path}/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/common/utils/include", - "${services_path}/screentransport/screensourcetrans/include", - "${services_path}/screentransport/screendatachannel/include", - "${services_path}/screentransport/screensourceprocessor/include", - "${services_path}/screentransport/screensourceprocessor/encoder/include", - "${services_path}/softbusadapter/include", - ] - - deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributed_av_receiver", - "distributed_hardware_fwk:libdhfwk_sdk", - "dsoftbus:softbus_client", - "hilog:libhilog", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnSessionOpenedFuzzTest\"", - "LOG_DOMAIN=0xD004140", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnSessionOpenedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2023 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/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp deleted file mode 100644 index a77c3251..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.cpp +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright (c) 2023-2024 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 "softbusonsessionopened_fuzzer.h" - -#include - -#include "dscreen_constants.h" -#include "dscreen_errcode.h" -#include "dscreen_util.h" -#include "isoftbus_listener.h" -#include "softbus_bus_center.h" -#include "softbus_common.h" -#include "softbus_adapter.h" - -namespace OHOS { -namespace DistributedHardware { - namespace { - const std::string PEER_SESSION_NAME = "ohos.dhardware.dscreen.session8647073e02e7a78f09473aa124"; - const std::string REMOTE_DEV_ID = "f6d4c0864707aefte7a78f09473aa122ff57fc81c00981fcf5be989e7d112124"; - const std::string DSCREEN_PKG_NAME_TEST = "ohos.dhardware.dscreen"; -} -void SoftbusOnSessionOpenedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - int32_t sessionId = *(reinterpret_cast(data)); - PeerSocketInfo peerSocketInfo = { - .name = const_cast(PEER_SESSION_NAME.c_str()), - .networkId = const_cast(REMOTE_DEV_ID.c_str()), - .pkgName = const_cast(DSCREEN_PKG_NAME_TEST.c_str()), - .dataType = DATA_TYPE_BYTES - }; - std::shared_ptr adapter = std::make_shared(); - adapter->OnSoftbusSessionOpened(sessionId, peerSocketInfo); -} -} // namespace DistributedHardware -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SoftbusOnSessionOpenedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h deleted file mode 100644 index 8dbb5a98..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonsessionopened_fuzzer/softbusonsessionopened_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 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 SOFTBUSONSESSIONOPENED_FUZZER_H -#define SOFTBUSONSESSIONOPENED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonsessionopened_fuzzer" - -#endif \ No newline at end of file diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn deleted file mode 100644 index 7d6f7107..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/BUILD.gn +++ /dev/null @@ -1,63 +0,0 @@ -# Copyright (c) 2023-2024 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("../../../../../distributedscreen.gni") - -##############################fuzztest########################################## -ohos_fuzztest("SoftbusOnStreamReceivedFuzzTest") { - module_out_path = "${fuzz_test_path}/softbusadapter" - fuzz_config_file = "${services_path}/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer" - - configs = - [ "${common_path}/test/unittest/resource:dscreen_unittest_public_config" ] - - sources = [ "softbusonstreamreceived_fuzzer.cpp" ] - - include_dirs = [ - "${common_path}/include", - "${services_path}/common/databuffer/include", - "${services_path}/common/screen_channel/include", - "${services_path}/common/utils/include", - "${services_path}/screentransport/screensourcetrans/include", - "${services_path}/screentransport/screendatachannel/include", - "${services_path}/screentransport/screensourceprocessor/include", - "${services_path}/screentransport/screensourceprocessor/encoder/include", - "${services_path}/softbusadapter/include", - ] - - deps = [ "${services_path}/screentransport/screensinktrans:distributed_screen_sinktrans" ] - - external_deps = [ - "c_utils:utils", - "distributed_hardware_fwk:distributed_av_receiver", - "distributed_hardware_fwk:libdhfwk_sdk", - "dsoftbus:softbus_client", - "hilog:libhilog", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"SoftbusOnStreamReceivedFuzzTest\"", - "LOG_DOMAIN=0xD004140", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - deps = [ ":SoftbusOnStreamReceivedFuzzTest" ] -} -############################################################################### diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init deleted file mode 100644 index 2b595da0..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2023 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/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml deleted file mode 100644 index 4fdbc407..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp deleted file mode 100644 index ea186972..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.cpp +++ /dev/null @@ -1,50 +0,0 @@ -/* - * Copyright (c) 2023-2024 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 "softbusonstreamreceived_fuzzer.h" - -#include "dscreen_constants.h" -#include "dscreen_errcode.h" -#include "dscreen_util.h" -#include "isoftbus_listener.h" -#include "softbus_bus_center.h" -#include "softbus_common.h" -#include "softbus_adapter.h" - -namespace OHOS { -namespace DistributedHardware { -void SoftbusOnStreamReceivedFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < (sizeof(int32_t)))) { - return; - } - int32_t sessionId = *(reinterpret_cast(data)); - StreamData *stream = nullptr; - StreamData *ext = nullptr; - StreamFrameInfo *info = nullptr; - std::shared_ptr adapter = std::make_shared(); - adapter->OnStreamReceived(sessionId, stream, ext, info); -} -} // namespace DistributedHardware -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::SoftbusOnStreamReceivedFuzzTest(data, size); - return 0; -} - diff --git a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h b/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h deleted file mode 100644 index 245aaab3..00000000 --- a/services/softbusadapter/test/fuzztest/softbusonstreamreceived_fuzzer/softbusonstreamreceived_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2023 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 SOFTBUSONBYTESRECEIVED_FUZZER_H -#define SOFTBUSONBYTESRECEIVED_FUZZER_H - -#define FUZZ_PROJECT_NAME "softbusonbytesreceived_fuzzer" - -#endif \ No newline at end of file -- Gitee