From 0d9954809dde02128dc3da2e89470c4f892788df Mon Sep 17 00:00:00 2001 From: wangbin Date: Wed, 25 Jun 2025 11:02:31 +0800 Subject: [PATCH 1/2] add fuzz Signed-off-by: wangbin --- .../networkdelegatenormalimpl_fuzzer/BUILD.gn | 67 ++++++++++ .../corpus/init | 16 +++ .../networkdelegatenormalimpl_fuzzer.cpp | 89 +++++++++++++ .../networkdelegatenormalimpl_fuzzer.h | 21 +++ .../project.xml | 25 ++++ .../test/fuzztest/screenlock_fuzzer/BUILD.gn | 55 ++++++++ .../fuzztest/screenlock_fuzzer/corpus/init | 16 +++ .../fuzztest/screenlock_fuzzer/project.xml | 25 ++++ .../screenlock_fuzzer/screenlock_fuzzer.cpp | 123 ++++++++++++++++++ .../screenlock_fuzzer/screenlock_fuzzer.h | 21 +++ .../adapter/test/BUILD.gn | 9 +- 11 files changed, 465 insertions(+), 2 deletions(-) create mode 100644 services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/corpus/init create mode 100644 services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.cpp create mode 100644 services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.h create mode 100644 services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/project.xml create mode 100644 services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/corpus/init create mode 100644 services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/project.xml create mode 100644 services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.cpp create mode 100644 services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.h diff --git a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/BUILD.gn b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/BUILD.gn new file mode 100644 index 000000000..6dcd6a6d2 --- /dev/null +++ b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/BUILD.gn @@ -0,0 +1,67 @@ +# Copyright (c) 2025 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/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("NetworkDelegateNormalImplFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + fuzz_config_file = "${data_service_path}/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer" + + sources = [ + "${data_service_path}/framework/network/network_delegate.cpp", + "networkdelegatenormalimpl_fuzzer.cpp", + ] + + cflags = [ + "-Dprivate=public", + "-Dprotected=public", + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + include_dirs = [ + "${data_service_path}/adapter/include/communicator", + "${data_service_path}/framework/include/network", + "${data_service_path}/adapter/include/utils", + "${data_service_path}/framework/include", + "${data_service_path}/adapter/network/src", + "${data_service_path}/adapter/include", + ] + + deps = [ + "${data_service_path}/adapter/communicator:distributeddata_communicator", + ] + + external_deps = [ + "c_utils:utils", + "device_manager:devicemanagersdk", + "hilog:libhilog", + "ipc:ipc_core", + "kv_store:datamgr_common", + "netmanager_base:net_conn_manager_if", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":NetworkDelegateNormalImplFuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/corpus/init b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/corpus/init new file mode 100644 index 000000000..7ade8a0fa --- /dev/null +++ b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.cpp b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.cpp new file mode 100644 index 000000000..f06ce4a59 --- /dev/null +++ b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.cpp @@ -0,0 +1,89 @@ +/* + * Copyright (c) 2025 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 +#include "network_delegate.h" +#include "network_delegate_normal_impl.h" +#include "network_delegate_normal_impl.cpp" +#include + +using namespace OHOS::DistributedData; + +namespace OHOS { +void GetNetworkTypeFuzz(FuzzedDataProvider &provider) +{ + NetworkDelegateNormalImpl delegate; + delegate.Init(); + bool retrieve = provider.ConsumeIntegral(); + delegate.GetNetworkType(retrieve); + + sptr observer = new (std::nothrow) NetConnCallbackObserver(delegate); + sptr netHandle = new (std::nothrow) NetHandle(); + sptr netAllCap = new (std::nothrow) NetAllCapabilities(); + observer->NetCapabilitiesChange(netHandle, netAllCap); + netAllCap->netCaps_.insert(NetManagerStandard::NET_CAPABILITY_VALIDATED); + observer->NetCapabilitiesChange(netHandle, netAllCap); + observer->NetAvailable(netHandle); + observer->NetUnavailable(); +} + +void GetTaskFuzz(FuzzedDataProvider &provider) +{ + NetworkDelegateNormalImpl delegate; + delegate.Init(); + uint32_t retry = provider.ConsumeIntegral(); + delegate.GetTask(retry); + + sptr observer = new (std::nothrow) NetConnCallbackObserver(delegate); + sptr netHandle = new (std::nothrow) NetHandle(); + sptr info = new (std::nothrow) NetLinkInfo(); + observer->NetConnectionPropertiesChange(netHandle, info); + observer->NetLost(netHandle); + delegate.RegOnNetworkChange(); +} + +void BindExecutorFuzz(FuzzedDataProvider &provider) +{ + NetworkDelegateNormalImpl delegate; + delegate.Init(); + size_t max = provider.ConsumeIntegralInRange(12, 15); + size_t min = provider.ConsumeIntegralInRange(5, 8); + auto executor = std::make_shared(max, min); + delegate.BindExecutor(executor); + delegate.IsNetworkAvailable(); +} + +void NetBlockStatusChangeFuzz(FuzzedDataProvider &provider) +{ + NetworkDelegateNormalImpl delegate; + delegate.Init(); + sptr observer = new (std::nothrow) NetConnCallbackObserver(delegate); + sptr netHandle = nullptr; + bool blocked = provider.ConsumeIntegral(); + observer->NetBlockStatusChange(netHandle, blocked); + delegate.RefreshNet(); +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::GetNetworkTypeFuzz(provider); + OHOS::GetTaskFuzz(provider); + OHOS::BindExecutorFuzz(provider); + OHOS::NetBlockStatusChangeFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.h b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.h new file mode 100644 index 000000000..1ae55e23e --- /dev/null +++ b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 NETWORKDELEGATENORMALIMPL_FUZZER_H +#define NETWORKDELEGATENORMALIMPL_FUZZER_H + +#define FUZZ_PROJECT_NAME "networkdelegatenormalimpl_fuzzer" + +#endif // NETWORKDELEGATENORMALIMPL_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/project.xml b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/project.xml new file mode 100644 index 000000000..a37a23b15 --- /dev/null +++ b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/BUILD.gn b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/BUILD.gn new file mode 100644 index 000000000..ef3c097db --- /dev/null +++ b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/BUILD.gn @@ -0,0 +1,55 @@ +# Copyright (c) 2025 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/distributeddatamgr/datamgr_service/datamgr_service.gni") + +##############################fuzztest########################################## +ohos_fuzztest("ScreenlockFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + fuzz_config_file = + "${data_service_path}/adapter/screenlock/test/fuzztest/screenlock_fuzzer" + + sources = [ "screenlock_fuzzer.cpp" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-Dprivate=public", + "-Dprotected=public", + ] + + deps = [ + "${data_service_path}/adapter/screenlock:distributeddata_screenlock", + "${data_service_path}/framework:distributeddatasvcfwk", + ] + + external_deps = [ + "c_utils:utils", + "common_event_service:cesfwk_innerkits", + "hilog:libhilog", + "kv_store:datamgr_common", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":ScreenlockFuzzTest" ] +} +############################################################################### diff --git a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/corpus/init b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/corpus/init new file mode 100644 index 000000000..7ade8a0fa --- /dev/null +++ b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/corpus/init @@ -0,0 +1,16 @@ +/* + * Copyright (c) 2025 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/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/project.xml b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/project.xml new file mode 100644 index 000000000..a37a23b15 --- /dev/null +++ b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.cpp b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.cpp new file mode 100644 index 000000000..0b64147db --- /dev/null +++ b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.cpp @@ -0,0 +1,123 @@ +/* + * Copyright (c) 2025 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 +#include "screenlock_fuzzer.h" +#include "screenlock/screen_lock.h" + +using namespace OHOS::DistributedData; +namespace OHOS { +class ScreenLockObserver : public ScreenManager::Observer { +public: + void OnScreenUnlocked(int32_t user) override + { + } + + std::string GetName() override + { + return name_; + } + + void SetName(const std::string &name) + { + name_ = name; + } + +private: + std::string name_ = "screenTestObserver"; +}; + +void SubscribeFuzz(FuzzedDataProvider &provider) +{ + auto screenLock = std::make_shared(); + screenLock->Subscribe(nullptr); + auto observer = std::make_shared(); + std::string name = provider.ConsumeRandomLengthString(); + observer->SetName(name); + screenLock->Subscribe(observer); + screenLock->IsLocked(); +} + +void UnsubscribeFuzz(FuzzedDataProvider &provider) +{ + auto screenLock = std::make_shared(); + auto observer = std::make_shared(); + std::string name = provider.ConsumeRandomLengthString(); + observer->SetName(name); + screenLock->Subscribe(observer); + screenLock->Unsubscribe(observer); + screenLock->UnsubscribeScreenEvent(); +} + +void GetTaskFuzz(FuzzedDataProvider &provider) +{ + auto screenLock = std::make_shared(); + int retry = provider.ConsumeIntegralInRange(1, 20); + screenLock->GetTask(retry); +} + +void NotifyScreenUnlockedFuzz(FuzzedDataProvider &provider) +{ + auto screenLock = std::make_shared(); + int user = provider.ConsumeIntegral(); + screenLock->NotifyScreenUnlocked(user); +} + +void SetEventCallbackFuzz(FuzzedDataProvider &provider) +{ + OHOS::EventFwk::MatchingSkills matchingSkills; + matchingSkills.AddEvent("com.example.SCREEN_LOCK_EVENT"); + OHOS::EventFwk::CommonEventSubscribeInfo info(matchingSkills); + int priority = provider.ConsumeIntegral(); + info.SetPriority(priority); + info.SetPermission("ohos.permission.SUBSCRIBE_SCREEN_LOCK"); + auto subscriber = std::make_shared(info); + int32_t local_user_id = 1001; + auto callback = [local_user_id](int32_t user) mutable { + local_user_id = user; + }; + subscriber->SetEventCallback(callback); +} + +void OnReceiveEventFuzz(FuzzedDataProvider &provider) +{ + OHOS::EventFwk::MatchingSkills matchingSkills; + std::string reserved = provider.ConsumeRandomLengthString(); + matchingSkills.AddEvent(reserved); + OHOS::EventFwk::CommonEventSubscribeInfo info(matchingSkills); + int priority = provider.ConsumeIntegral(); + info.SetPriority(priority); + info.SetPermission("ohos.permission.SUBSCRIBE_SCREEN_LOCK"); + auto subscriber = std::make_shared(info); + OHOS::AAFwk::Want want; + want.SetAction(CommonEventSupport::COMMON_EVENT_HWID_LOGIN); + CommonEventData commonEventData(want); + CommonEventData event(want); + subscriber->OnReceiveEvent(event); +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::SubscribeFuzz(provider); + OHOS::UnsubscribeFuzz(provider); + OHOS::GetTaskFuzz(provider); + OHOS::NotifyScreenUnlockedFuzz(provider); + OHOS::SetEventCallbackFuzz(provider); + OHOS::OnReceiveEventFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.h b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.h new file mode 100644 index 000000000..2ae3c12cd --- /dev/null +++ b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.h @@ -0,0 +1,21 @@ +/* + * Copyright (c) 2025 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 SCREENLOCK_FUZZER_H +#define SCREENLOCK_FUZZER_H + +#define FUZZ_PROJECT_NAME "screenlock_fuzzer" + +#endif // SCREENLOCK_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/adapter/test/BUILD.gn b/services/distributeddataservice/adapter/test/BUILD.gn index db76543eb..8442da87f 100755 --- a/services/distributeddataservice/adapter/test/BUILD.gn +++ b/services/distributeddataservice/adapter/test/BUILD.gn @@ -24,7 +24,8 @@ group("unittest") { "../dfx/test:unittest", ] - if (defined(global_parts_info) && defined(global_parts_info.theme_screenlock_mgr)) { + if (defined(global_parts_info) && + defined(global_parts_info.theme_screenlock_mgr)) { deps += [ "${data_service_path}/adapter/screenlock/test:unittest" ] } @@ -36,5 +37,9 @@ group("unittest") { group("fuzztest") { testonly = true - deps = [ "../communicator/test/fuzztest:fuzztest" ] + deps = [ + "../communicator/test/fuzztest:fuzztest", + "../network/test/fuzztest/networkdelegatenormalimpl_fuzzer:fuzztest", + "../screenlock/test/fuzztest/screenlock_fuzzer:fuzztest", + ] } -- Gitee From d7f783e36a3455c08875f320b61794500b2ef62d Mon Sep 17 00:00:00 2001 From: wangbin Date: Wed, 25 Jun 2025 15:27:39 +0800 Subject: [PATCH 2/2] Revert "add fuzz" This reverts commit 0d9954809dde02128dc3da2e89470c4f892788df. --- .../softbusadapter_fuzzer.cpp | 1 - .../networkdelegatenormalimpl_fuzzer/BUILD.gn | 67 ---------- .../corpus/init | 16 --- .../networkdelegatenormalimpl_fuzzer.cpp | 89 ------------- .../networkdelegatenormalimpl_fuzzer.h | 21 --- .../project.xml | 25 ---- .../test/fuzztest/screenlock_fuzzer/BUILD.gn | 55 -------- .../fuzztest/screenlock_fuzzer/corpus/init | 16 --- .../fuzztest/screenlock_fuzzer/project.xml | 25 ---- .../screenlock_fuzzer/screenlock_fuzzer.cpp | 123 ------------------ .../screenlock_fuzzer/screenlock_fuzzer.h | 21 --- .../adapter/test/BUILD.gn | 9 +- 12 files changed, 2 insertions(+), 466 deletions(-) delete mode 100644 services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/BUILD.gn delete mode 100644 services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/corpus/init delete mode 100644 services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.cpp delete mode 100644 services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.h delete mode 100644 services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/project.xml delete mode 100644 services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/BUILD.gn delete mode 100644 services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/corpus/init delete mode 100644 services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/project.xml delete mode 100644 services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.cpp delete mode 100644 services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.h diff --git a/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp b/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp index 03e0db571..00ba27f1d 100644 --- a/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp +++ b/services/distributeddataservice/adapter/communicator/test/fuzztest/softbusadapter_fuzzer/softbusadapter_fuzzer.cpp @@ -19,7 +19,6 @@ #include #include - #include "message_parcel.h" #include "securec.h" #include "softbus_adapter_standard.cpp" diff --git a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/BUILD.gn b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/BUILD.gn deleted file mode 100644 index 6dcd6a6d2..000000000 --- a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/BUILD.gn +++ /dev/null @@ -1,67 +0,0 @@ -# Copyright (c) 2025 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/distributeddatamgr/datamgr_service/datamgr_service.gni") - -##############################fuzztest########################################## -ohos_fuzztest("NetworkDelegateNormalImplFuzzTest") { - module_out_path = "datamgr_service/datamgr_service" - - fuzz_config_file = "${data_service_path}/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer" - - sources = [ - "${data_service_path}/framework/network/network_delegate.cpp", - "networkdelegatenormalimpl_fuzzer.cpp", - ] - - cflags = [ - "-Dprivate=public", - "-Dprotected=public", - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - include_dirs = [ - "${data_service_path}/adapter/include/communicator", - "${data_service_path}/framework/include/network", - "${data_service_path}/adapter/include/utils", - "${data_service_path}/framework/include", - "${data_service_path}/adapter/network/src", - "${data_service_path}/adapter/include", - ] - - deps = [ - "${data_service_path}/adapter/communicator:distributeddata_communicator", - ] - - external_deps = [ - "c_utils:utils", - "device_manager:devicemanagersdk", - "hilog:libhilog", - "ipc:ipc_core", - "kv_store:datamgr_common", - "netmanager_base:net_conn_manager_if", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - - deps = [ ":NetworkDelegateNormalImplFuzzTest" ] -} -############################################################################### diff --git a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/corpus/init b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/corpus/init deleted file mode 100644 index 7ade8a0fa..000000000 --- a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2025 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/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.cpp b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.cpp deleted file mode 100644 index f06ce4a59..000000000 --- a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.cpp +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright (c) 2025 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 -#include "network_delegate.h" -#include "network_delegate_normal_impl.h" -#include "network_delegate_normal_impl.cpp" -#include - -using namespace OHOS::DistributedData; - -namespace OHOS { -void GetNetworkTypeFuzz(FuzzedDataProvider &provider) -{ - NetworkDelegateNormalImpl delegate; - delegate.Init(); - bool retrieve = provider.ConsumeIntegral(); - delegate.GetNetworkType(retrieve); - - sptr observer = new (std::nothrow) NetConnCallbackObserver(delegate); - sptr netHandle = new (std::nothrow) NetHandle(); - sptr netAllCap = new (std::nothrow) NetAllCapabilities(); - observer->NetCapabilitiesChange(netHandle, netAllCap); - netAllCap->netCaps_.insert(NetManagerStandard::NET_CAPABILITY_VALIDATED); - observer->NetCapabilitiesChange(netHandle, netAllCap); - observer->NetAvailable(netHandle); - observer->NetUnavailable(); -} - -void GetTaskFuzz(FuzzedDataProvider &provider) -{ - NetworkDelegateNormalImpl delegate; - delegate.Init(); - uint32_t retry = provider.ConsumeIntegral(); - delegate.GetTask(retry); - - sptr observer = new (std::nothrow) NetConnCallbackObserver(delegate); - sptr netHandle = new (std::nothrow) NetHandle(); - sptr info = new (std::nothrow) NetLinkInfo(); - observer->NetConnectionPropertiesChange(netHandle, info); - observer->NetLost(netHandle); - delegate.RegOnNetworkChange(); -} - -void BindExecutorFuzz(FuzzedDataProvider &provider) -{ - NetworkDelegateNormalImpl delegate; - delegate.Init(); - size_t max = provider.ConsumeIntegralInRange(12, 15); - size_t min = provider.ConsumeIntegralInRange(5, 8); - auto executor = std::make_shared(max, min); - delegate.BindExecutor(executor); - delegate.IsNetworkAvailable(); -} - -void NetBlockStatusChangeFuzz(FuzzedDataProvider &provider) -{ - NetworkDelegateNormalImpl delegate; - delegate.Init(); - sptr observer = new (std::nothrow) NetConnCallbackObserver(delegate); - sptr netHandle = nullptr; - bool blocked = provider.ConsumeIntegral(); - observer->NetBlockStatusChange(netHandle, blocked); - delegate.RefreshNet(); -} -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - FuzzedDataProvider provider(data, size); - OHOS::GetNetworkTypeFuzz(provider); - OHOS::GetTaskFuzz(provider); - OHOS::BindExecutorFuzz(provider); - OHOS::NetBlockStatusChangeFuzz(provider); - return 0; -} \ No newline at end of file diff --git a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.h b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.h deleted file mode 100644 index 1ae55e23e..000000000 --- a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/networkdelegatenormalimpl_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2025 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 NETWORKDELEGATENORMALIMPL_FUZZER_H -#define NETWORKDELEGATENORMALIMPL_FUZZER_H - -#define FUZZ_PROJECT_NAME "networkdelegatenormalimpl_fuzzer" - -#endif // NETWORKDELEGATENORMALIMPL_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/project.xml b/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/project.xml deleted file mode 100644 index a37a23b15..000000000 --- a/services/distributeddataservice/adapter/network/test/fuzztest/networkdelegatenormalimpl_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - \ No newline at end of file diff --git a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/BUILD.gn b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/BUILD.gn deleted file mode 100644 index ef3c097db..000000000 --- a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/BUILD.gn +++ /dev/null @@ -1,55 +0,0 @@ -# Copyright (c) 2025 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/distributeddatamgr/datamgr_service/datamgr_service.gni") - -##############################fuzztest########################################## -ohos_fuzztest("ScreenlockFuzzTest") { - module_out_path = "datamgr_service/datamgr_service" - - fuzz_config_file = - "${data_service_path}/adapter/screenlock/test/fuzztest/screenlock_fuzzer" - - sources = [ "screenlock_fuzzer.cpp" ] - - cflags = [ - "-g", - "-O0", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - "-Dprivate=public", - "-Dprotected=public", - ] - - deps = [ - "${data_service_path}/adapter/screenlock:distributeddata_screenlock", - "${data_service_path}/framework:distributeddatasvcfwk", - ] - - external_deps = [ - "c_utils:utils", - "common_event_service:cesfwk_innerkits", - "hilog:libhilog", - "kv_store:datamgr_common", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - - deps = [ ":ScreenlockFuzzTest" ] -} -############################################################################### diff --git a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/corpus/init b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/corpus/init deleted file mode 100644 index 7ade8a0fa..000000000 --- a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/corpus/init +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2025 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/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/project.xml b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/project.xml deleted file mode 100644 index a37a23b15..000000000 --- a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - \ No newline at end of file diff --git a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.cpp b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.cpp deleted file mode 100644 index 0b64147db..000000000 --- a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.cpp +++ /dev/null @@ -1,123 +0,0 @@ -/* - * Copyright (c) 2025 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 -#include "screenlock_fuzzer.h" -#include "screenlock/screen_lock.h" - -using namespace OHOS::DistributedData; -namespace OHOS { -class ScreenLockObserver : public ScreenManager::Observer { -public: - void OnScreenUnlocked(int32_t user) override - { - } - - std::string GetName() override - { - return name_; - } - - void SetName(const std::string &name) - { - name_ = name; - } - -private: - std::string name_ = "screenTestObserver"; -}; - -void SubscribeFuzz(FuzzedDataProvider &provider) -{ - auto screenLock = std::make_shared(); - screenLock->Subscribe(nullptr); - auto observer = std::make_shared(); - std::string name = provider.ConsumeRandomLengthString(); - observer->SetName(name); - screenLock->Subscribe(observer); - screenLock->IsLocked(); -} - -void UnsubscribeFuzz(FuzzedDataProvider &provider) -{ - auto screenLock = std::make_shared(); - auto observer = std::make_shared(); - std::string name = provider.ConsumeRandomLengthString(); - observer->SetName(name); - screenLock->Subscribe(observer); - screenLock->Unsubscribe(observer); - screenLock->UnsubscribeScreenEvent(); -} - -void GetTaskFuzz(FuzzedDataProvider &provider) -{ - auto screenLock = std::make_shared(); - int retry = provider.ConsumeIntegralInRange(1, 20); - screenLock->GetTask(retry); -} - -void NotifyScreenUnlockedFuzz(FuzzedDataProvider &provider) -{ - auto screenLock = std::make_shared(); - int user = provider.ConsumeIntegral(); - screenLock->NotifyScreenUnlocked(user); -} - -void SetEventCallbackFuzz(FuzzedDataProvider &provider) -{ - OHOS::EventFwk::MatchingSkills matchingSkills; - matchingSkills.AddEvent("com.example.SCREEN_LOCK_EVENT"); - OHOS::EventFwk::CommonEventSubscribeInfo info(matchingSkills); - int priority = provider.ConsumeIntegral(); - info.SetPriority(priority); - info.SetPermission("ohos.permission.SUBSCRIBE_SCREEN_LOCK"); - auto subscriber = std::make_shared(info); - int32_t local_user_id = 1001; - auto callback = [local_user_id](int32_t user) mutable { - local_user_id = user; - }; - subscriber->SetEventCallback(callback); -} - -void OnReceiveEventFuzz(FuzzedDataProvider &provider) -{ - OHOS::EventFwk::MatchingSkills matchingSkills; - std::string reserved = provider.ConsumeRandomLengthString(); - matchingSkills.AddEvent(reserved); - OHOS::EventFwk::CommonEventSubscribeInfo info(matchingSkills); - int priority = provider.ConsumeIntegral(); - info.SetPriority(priority); - info.SetPermission("ohos.permission.SUBSCRIBE_SCREEN_LOCK"); - auto subscriber = std::make_shared(info); - OHOS::AAFwk::Want want; - want.SetAction(CommonEventSupport::COMMON_EVENT_HWID_LOGIN); - CommonEventData commonEventData(want); - CommonEventData event(want); - subscriber->OnReceiveEvent(event); -} -} // namespace OHOS - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) -{ - FuzzedDataProvider provider(data, size); - OHOS::SubscribeFuzz(provider); - OHOS::UnsubscribeFuzz(provider); - OHOS::GetTaskFuzz(provider); - OHOS::NotifyScreenUnlockedFuzz(provider); - OHOS::SetEventCallbackFuzz(provider); - OHOS::OnReceiveEventFuzz(provider); - return 0; -} \ No newline at end of file diff --git a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.h b/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.h deleted file mode 100644 index 2ae3c12cd..000000000 --- a/services/distributeddataservice/adapter/screenlock/test/fuzztest/screenlock_fuzzer/screenlock_fuzzer.h +++ /dev/null @@ -1,21 +0,0 @@ -/* - * Copyright (c) 2025 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 SCREENLOCK_FUZZER_H -#define SCREENLOCK_FUZZER_H - -#define FUZZ_PROJECT_NAME "screenlock_fuzzer" - -#endif // SCREENLOCK_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/adapter/test/BUILD.gn b/services/distributeddataservice/adapter/test/BUILD.gn index 8442da87f..db76543eb 100755 --- a/services/distributeddataservice/adapter/test/BUILD.gn +++ b/services/distributeddataservice/adapter/test/BUILD.gn @@ -24,8 +24,7 @@ group("unittest") { "../dfx/test:unittest", ] - if (defined(global_parts_info) && - defined(global_parts_info.theme_screenlock_mgr)) { + if (defined(global_parts_info) && defined(global_parts_info.theme_screenlock_mgr)) { deps += [ "${data_service_path}/adapter/screenlock/test:unittest" ] } @@ -37,9 +36,5 @@ group("unittest") { group("fuzztest") { testonly = true - deps = [ - "../communicator/test/fuzztest:fuzztest", - "../network/test/fuzztest/networkdelegatenormalimpl_fuzzer:fuzztest", - "../screenlock/test/fuzztest/screenlock_fuzzer:fuzztest", - ] + deps = [ "../communicator/test/fuzztest:fuzztest" ] } -- Gitee