From 7e86b77cbf11bc48f0d2d60cc696b52037294415 Mon Sep 17 00:00:00 2001 From: gecheng Date: Sat, 7 Jun 2025 21:43:11 +0800 Subject: [PATCH 01/10] =?UTF-8?q?=E8=A1=A5=E5=85=85FUZZ?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: gecheng --- .../fuzztest/cloudservicestub_fuzzer/BUILD.gn | 2 + .../cloudservicestub_fuzzer.cpp | 87 +++++++++++++++++++ 2 files changed, 89 insertions(+) diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn index 3f059f61a..551bc9b45 100644 --- a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn @@ -31,6 +31,7 @@ ohos_fuzztest("CloudServiceStubFuzzTest") { "${data_service_path}/service/permission/include", "${data_service_path}/service/rdb", "${data_service_path}/adapter/include/communicator", + "${data_service_path}/framework/include", ] fuzz_config_file = "${data_service_path}/service/test/fuzztest/cloudservicestub_fuzzer" @@ -40,6 +41,7 @@ ohos_fuzztest("CloudServiceStubFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", + "-fno-access-control", ] sources = [ diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp index 9e467e6bc..0578aad47 100644 --- a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp @@ -26,9 +26,13 @@ #include "message_parcel.h" #include "securec.h" #include "token_setproc.h" +#include "screen/screen_manager.h" +#include "sync_strategies/network_sync_strategy.h" +#include "metadata/store_debug_info.h" using namespace OHOS::CloudData; using namespace OHOS::Security::AccessToken; +using namespace OHOS::DistributedData; namespace OHOS { constexpr int USER_ID = 100; @@ -67,6 +71,84 @@ void AllocAndSetHapToken() SetSelfTokenID(tokenID.tokenIDEx); } +void TestScreenManager(FuzzedDataProvider &provider) +{ + ScreenManager::GetInstance()->Subscribe(nullptr); + ScreenManager::GetInstance()->Unsubscribe(nullptr); + ScreenManager::GetInstance()->BindExecutor(nullptr); + ScreenManager::GetInstance()->SubscribeScreenEvent(); + ScreenManager::GetInstance()->UnsubscribeScreenEvent(); +} + +void SyncStrategiesFuzz(FuzzedDataProvider &provider) +{ + int32_t user = provider.ConsumeIntegral(); + std::string bundleName = provider.ConsumeRandomLengthString(); + NetworkSyncStrategy strategy; + StoreInfo storeInfo; + storeInfo.user = user; + storeInfo.bundleName = bundleName; + strategy.CheckSyncAction(storeInfo); +} + +void SyncStrategiesFuzz001(FuzzedDataProvider &provider) +{ + uint32_t strategy = provider.ConsumeIntegral(); + NetworkSyncStrategy strategyInstance; + strategyInstance.Check(strategy); +} + +void SyncStrategiesFuzz002(FuzzedDataProvider &provider) +{ + int32_t user = provider.ConsumeIntegral(); + std::string bundleName = provider.ConsumeRandomLengthString(); + NetworkSyncStrategy strategyInstance; + strategyInstance.GetStrategy(user, bundleName); + strategyInstance.Getkey(user); + NetworkSyncStrategy::StrategyInfo info; + info.user = 1; + info.bundleName = "StrategyInfo"; + info.Marshal(nullptr); + Serializable::json node; + std::string key = provider.ConsumeRandomLengthString(); + std::string valueStr = provider.ConsumeRandomLengthString(); + int valueInt = provider.ConsumeIntegral(); + float valueFloat = provider.ConsumeFloatingPoint(); + bool valueBool = provider.ConsumeBool(); + int valueRange = provider.ConsumeIntegralInRange(0, 100); + node[key] = valueStr; + node["integer"] = valueInt; + node["float"] = valueFloat; + node["bool"] = valueBool; + node["range"] = valueRange; + info.Marshal(node); + info.Unmarshal(node); +} + +void StoreDebugInfoFuzz(FuzzedDataProvider &provider) +{ + StoreDebugInfo::FileInfo fileInfo; + StoreDebugInfo debugInfo; + std::string fileName = "fileName"; + debugInfo.fileInfos.insert(std::make_pair(fileName, fileInfo)); + Serializable::json node; + std::string key = provider.ConsumeRandomLengthString(); + std::string valueStr = provider.ConsumeRandomLengthString(); + int valueInt = provider.ConsumeIntegral(); + float valueFloat = provider.ConsumeFloatingPoint(); + bool valueBool = provider.ConsumeBool(); + int valueRange = provider.ConsumeIntegralInRange(0, 100); + node[key] = valueStr; + node["integer"] = valueInt; + node["float"] = valueFloat; + node["bool"] = valueBool; + node["range"] = valueRange; + fileInfo.Marshal(node); + fileInfo.Unmarshal(node); + debugInfo.Marshal(node); + debugInfo.Unmarshal(node); +} + bool OnRemoteRequestFuzz(FuzzedDataProvider &provider) { std::shared_ptr cloudServiceImpl = std::make_shared(); @@ -93,6 +175,11 @@ bool OnRemoteRequestFuzz(FuzzedDataProvider &provider) extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { FuzzedDataProvider provider(data, size); + OHOS::TestScreenManager(provider); + OHOS::SyncStrategiesFuzz(provider); + OHOS::SyncStrategiesFuzz001(provider); + OHOS::SyncStrategiesFuzz002(provider); + OHOS::StoreDebugInfoFuzz(provider); OHOS::OnRemoteRequestFuzz(provider); return 0; } \ No newline at end of file -- Gitee From 256dc363b61a0652a3b6afb598ff134033c4c78e Mon Sep 17 00:00:00 2001 From: gecheng Date: Mon, 9 Jun 2025 09:44:19 +0800 Subject: [PATCH 02/10] =?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: gecheng --- .../cloudservicestub_fuzzer.cpp | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp index 0578aad47..5155e40ad 100644 --- a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp @@ -73,27 +73,27 @@ void AllocAndSetHapToken() void TestScreenManager(FuzzedDataProvider &provider) { - ScreenManager::GetInstance()->Subscribe(nullptr); - ScreenManager::GetInstance()->Unsubscribe(nullptr); - ScreenManager::GetInstance()->BindExecutor(nullptr); - ScreenManager::GetInstance()->SubscribeScreenEvent(); - ScreenManager::GetInstance()->UnsubscribeScreenEvent(); + ScreenManager::GetInstance()->Subscribe(nullptr); + ScreenManager::GetInstance()->Unsubscribe(nullptr); + ScreenManager::GetInstance()->BindExecutor(nullptr); + ScreenManager::GetInstance()->SubscribeScreenEvent(); + ScreenManager::GetInstance()->UnsubscribeScreenEvent(); } void SyncStrategiesFuzz(FuzzedDataProvider &provider) { - int32_t user = provider.ConsumeIntegral(); - std::string bundleName = provider.ConsumeRandomLengthString(); - NetworkSyncStrategy strategy; - StoreInfo storeInfo; - storeInfo.user = user; - storeInfo.bundleName = bundleName; - strategy.CheckSyncAction(storeInfo); + int32_t user = provider.ConsumeIntegral(); + std::string bundleName = provider.ConsumeRandomLengthString(); + NetworkSyncStrategy strategy; + StoreInfo storeInfo; + storeInfo.user = user; + storeInfo.bundleName = bundleName; + strategy.CheckSyncAction(storeInfo); } void SyncStrategiesFuzz001(FuzzedDataProvider &provider) { - uint32_t strategy = provider.ConsumeIntegral(); + uint32_t strategy = provider.ConsumeIntegral(); NetworkSyncStrategy strategyInstance; strategyInstance.Check(strategy); } @@ -104,11 +104,11 @@ void SyncStrategiesFuzz002(FuzzedDataProvider &provider) std::string bundleName = provider.ConsumeRandomLengthString(); NetworkSyncStrategy strategyInstance; strategyInstance.GetStrategy(user, bundleName); - strategyInstance.Getkey(user); + strategyInstance.GetKey(user); + NetworkSyncStrategy::StrategyInfo info; info.user = 1; info.bundleName = "StrategyInfo"; - info.Marshal(nullptr); Serializable::json node; std::string key = provider.ConsumeRandomLengthString(); std::string valueStr = provider.ConsumeRandomLengthString(); @@ -119,7 +119,7 @@ void SyncStrategiesFuzz002(FuzzedDataProvider &provider) node[key] = valueStr; node["integer"] = valueInt; node["float"] = valueFloat; - node["bool"] = valueBool; + node["boolean"] = valueBool; node["range"] = valueRange; info.Marshal(node); info.Unmarshal(node); @@ -141,7 +141,7 @@ void StoreDebugInfoFuzz(FuzzedDataProvider &provider) node[key] = valueStr; node["integer"] = valueInt; node["float"] = valueFloat; - node["bool"] = valueBool; + node["boolean"] = valueBool; node["range"] = valueRange; fileInfo.Marshal(node); fileInfo.Unmarshal(node); -- Gitee From ec7ba5a30eefeba46edf4847a9d6cf0d48b06a3c Mon Sep 17 00:00:00 2001 From: gecheng Date: Mon, 9 Jun 2025 11:51:54 +0800 Subject: [PATCH 03/10] =?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: gecheng --- .../cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp index 5155e40ad..3a687b963 100644 --- a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp @@ -83,7 +83,7 @@ void TestScreenManager(FuzzedDataProvider &provider) void SyncStrategiesFuzz(FuzzedDataProvider &provider) { int32_t user = provider.ConsumeIntegral(); - std::string bundleName = provider.ConsumeRandomLengthString(); + std::string bundleName = provider.ConsumeRandomLengthString(); NetworkSyncStrategy strategy; StoreInfo storeInfo; storeInfo.user = user; -- Gitee From d20ce13154347bb02226161f35edc3bf7e77f742 Mon Sep 17 00:00:00 2001 From: gecheng Date: Mon, 9 Jun 2025 21:30:35 +0800 Subject: [PATCH 04/10] =?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: gecheng --- BUILD.gn | 1 + .../framework/test/fuzztest/BUILD.gn | 23 +++++ .../fuzztest/storedebuginfo_fuzzer/BUILD.gn | 55 ++++++++++++ .../storedebuginfo_fuzzer/corpus/init | 16 ++++ .../storedebuginfo_fuzzer/project.xml | 25 ++++++ .../storedebuginfo_fuzzer.cpp | 65 ++++++++++++++ .../storedebuginfo_fuzzer.h | 21 +++++ .../service/test/fuzztest/BUILD.gn | 5 +- .../fuzztest/cloudservicestub_fuzzer/BUILD.gn | 2 - .../cloudservicestub_fuzzer.cpp | 87 ------------------- .../fuzztest/syncstrategies_fuzzer/BUILD.gn | 65 ++++++++++++++ .../syncstrategies_fuzzer/corpus/init | 16 ++++ .../syncstrategies_fuzzer/project.xml | 25 ++++++ .../syncstrategies_fuzzer.cpp | 78 +++++++++++++++++ .../syncstrategies_fuzzer.h | 21 +++++ 15 files changed, 415 insertions(+), 90 deletions(-) create mode 100644 services/distributeddataservice/framework/test/fuzztest/BUILD.gn create mode 100644 services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/corpus/init create mode 100644 services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/project.xml create mode 100644 services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/storedebuginfo_fuzzer.cpp create mode 100644 services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/storedebuginfo_fuzzer.h create mode 100644 services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/corpus/init create mode 100644 services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/project.xml create mode 100644 services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/syncstrategies_fuzzer.cpp create mode 100644 services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/syncstrategies_fuzzer.h diff --git a/BUILD.gn b/BUILD.gn index 71f3ee228..6d80a18e1 100755 --- a/BUILD.gn +++ b/BUILD.gn @@ -31,6 +31,7 @@ group("fuzztest") { "services/distributeddataservice/adapter/test:fuzztest", "services/distributeddataservice/app/test/fuzztest:fuzztest", "services/distributeddataservice/service/test/fuzztest:fuzztest", + "services/distributeddataservice/framework/test/fuzztest:fuzztest", ] } ############################################################################### diff --git a/services/distributeddataservice/framework/test/fuzztest/BUILD.gn b/services/distributeddataservice/framework/test/fuzztest/BUILD.gn new file mode 100644 index 000000000..2a8920793 --- /dev/null +++ b/services/distributeddataservice/framework/test/fuzztest/BUILD.gn @@ -0,0 +1,23 @@ +# 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. + +import("//build/ohos.gni") +import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") + +######################################################################################### +group("fuzztest") { + testonly = true + + deps = [ "storedebuginfo_fuzzer:fuzztest" ] + +} \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/BUILD.gn new file mode 100644 index 000000000..fd6c2367f --- /dev/null +++ b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_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("StoreDebugInfoFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + ] + + fuzz_config_file = + "${data_service_path}/framework/test/fuzztest/storedebuginfo_fuzzer" + + sources = [ "storedebuginfo_fuzzer.cpp" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + deps = [ + "${data_service_path}/framework:distributeddatasvcfwk", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "kv_store:datamgr_common", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":StoreDebugInfoFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/corpus/init b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/corpus/init new file mode 100644 index 000000000..7ade8a0fa --- /dev/null +++ b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_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/framework/test/fuzztest/storedebuginfo_fuzzer/project.xml b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/project.xml new file mode 100644 index 000000000..a37a23b15 --- /dev/null +++ b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/storedebuginfo_fuzzer.cpp b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/storedebuginfo_fuzzer.cpp new file mode 100644 index 000000000..a3dd18a2d --- /dev/null +++ b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/storedebuginfo_fuzzer.cpp @@ -0,0 +1,65 @@ +/* + * 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 "storedebuginfo_fuzzer.h" +#include "screen/screen_manager.h" +#include "metadata/store_debug_info.h" + +using namespace OHOS::DistributedData; + +namespace OHOS { +void TestScreenManager(FuzzedDataProvider &provider) +{ + ScreenManager::GetInstance()->Subscribe(nullptr); + ScreenManager::GetInstance()->Unsubscribe(nullptr); + ScreenManager::GetInstance()->BindExecutor(nullptr); + ScreenManager::GetInstance()->SubscribeScreenEvent(); + ScreenManager::GetInstance()->UnsubscribeScreenEvent(); +} + +void StoreDebugInfoFuzz(FuzzedDataProvider &provider) +{ + StoreDebugInfo::FileInfo fileInfo; + StoreDebugInfo debugInfo; + std::string fileName = "filename"; + debugInfo.fileInfos.insert(std::make_pair(fileName, fileInfo)); + Serializable::json node; + std::string key = provider.ConsumeRandomLengthString(); + std::string valueStr = provider.ConsumeRandomLengthString(); + int valueInt = provider.ConsumeIntegral(); + float valueFloat = provider.ConsumeFloatingPoint(); + bool valueBool = provider.ConsumeBool(); + int valueRange = provider.ConsumeIntegralInRange(0, 100); + node[key] = valueStr; + node["integer"] = valueInt; + node["float"] = valueFloat; + node["boolean"] = valueBool; + node["range"] = valueRange; + fileInfo.Marshal(node); + fileInfo.Unmarshal(node); + debugInfo.Marshal(node); + debugInfo.Unmarshal(node); +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::TestScreenManager(provider); + OHOS::StoreDebugInfoFuzz(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/storedebuginfo_fuzzer.h b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/storedebuginfo_fuzzer.h new file mode 100644 index 000000000..152fe67a6 --- /dev/null +++ b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/storedebuginfo_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 STOREDEBUGINFO_FUZZER_H +#define STOREDEBUGINFO_FUZZER_H + +#define FUZZ_PROJECT_NAME "storedebuginfo_fuzzer" + +#endif // STOREDEBUGINFO_FUZZER_H \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/BUILD.gn index efc923524..c8ed8a7fb 100644 --- a/services/distributeddataservice/service/test/fuzztest/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/BUILD.gn @@ -21,7 +21,10 @@ group("fuzztest") { deps = [ "dumphelper_fuzzer:fuzztest" ] if (datamgr_service_cloud) { - deps += [ "cloudservicestub_fuzzer:fuzztest" ] + deps += [ + "cloudservicestub_fuzzer:fuzztest", + "syncstrategies_fuzzer", + ] } if (datamgr_service_object) { diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn index 551bc9b45..3f059f61a 100644 --- a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/BUILD.gn @@ -31,7 +31,6 @@ ohos_fuzztest("CloudServiceStubFuzzTest") { "${data_service_path}/service/permission/include", "${data_service_path}/service/rdb", "${data_service_path}/adapter/include/communicator", - "${data_service_path}/framework/include", ] fuzz_config_file = "${data_service_path}/service/test/fuzztest/cloudservicestub_fuzzer" @@ -41,7 +40,6 @@ ohos_fuzztest("CloudServiceStubFuzzTest") { "-O0", "-Wno-unused-variable", "-fno-omit-frame-pointer", - "-fno-access-control", ] sources = [ diff --git a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp index 3a687b963..9e467e6bc 100644 --- a/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp +++ b/services/distributeddataservice/service/test/fuzztest/cloudservicestub_fuzzer/cloudservicestub_fuzzer.cpp @@ -26,13 +26,9 @@ #include "message_parcel.h" #include "securec.h" #include "token_setproc.h" -#include "screen/screen_manager.h" -#include "sync_strategies/network_sync_strategy.h" -#include "metadata/store_debug_info.h" using namespace OHOS::CloudData; using namespace OHOS::Security::AccessToken; -using namespace OHOS::DistributedData; namespace OHOS { constexpr int USER_ID = 100; @@ -71,84 +67,6 @@ void AllocAndSetHapToken() SetSelfTokenID(tokenID.tokenIDEx); } -void TestScreenManager(FuzzedDataProvider &provider) -{ - ScreenManager::GetInstance()->Subscribe(nullptr); - ScreenManager::GetInstance()->Unsubscribe(nullptr); - ScreenManager::GetInstance()->BindExecutor(nullptr); - ScreenManager::GetInstance()->SubscribeScreenEvent(); - ScreenManager::GetInstance()->UnsubscribeScreenEvent(); -} - -void SyncStrategiesFuzz(FuzzedDataProvider &provider) -{ - int32_t user = provider.ConsumeIntegral(); - std::string bundleName = provider.ConsumeRandomLengthString(); - NetworkSyncStrategy strategy; - StoreInfo storeInfo; - storeInfo.user = user; - storeInfo.bundleName = bundleName; - strategy.CheckSyncAction(storeInfo); -} - -void SyncStrategiesFuzz001(FuzzedDataProvider &provider) -{ - uint32_t strategy = provider.ConsumeIntegral(); - NetworkSyncStrategy strategyInstance; - strategyInstance.Check(strategy); -} - -void SyncStrategiesFuzz002(FuzzedDataProvider &provider) -{ - int32_t user = provider.ConsumeIntegral(); - std::string bundleName = provider.ConsumeRandomLengthString(); - NetworkSyncStrategy strategyInstance; - strategyInstance.GetStrategy(user, bundleName); - strategyInstance.GetKey(user); - - NetworkSyncStrategy::StrategyInfo info; - info.user = 1; - info.bundleName = "StrategyInfo"; - Serializable::json node; - std::string key = provider.ConsumeRandomLengthString(); - std::string valueStr = provider.ConsumeRandomLengthString(); - int valueInt = provider.ConsumeIntegral(); - float valueFloat = provider.ConsumeFloatingPoint(); - bool valueBool = provider.ConsumeBool(); - int valueRange = provider.ConsumeIntegralInRange(0, 100); - node[key] = valueStr; - node["integer"] = valueInt; - node["float"] = valueFloat; - node["boolean"] = valueBool; - node["range"] = valueRange; - info.Marshal(node); - info.Unmarshal(node); -} - -void StoreDebugInfoFuzz(FuzzedDataProvider &provider) -{ - StoreDebugInfo::FileInfo fileInfo; - StoreDebugInfo debugInfo; - std::string fileName = "fileName"; - debugInfo.fileInfos.insert(std::make_pair(fileName, fileInfo)); - Serializable::json node; - std::string key = provider.ConsumeRandomLengthString(); - std::string valueStr = provider.ConsumeRandomLengthString(); - int valueInt = provider.ConsumeIntegral(); - float valueFloat = provider.ConsumeFloatingPoint(); - bool valueBool = provider.ConsumeBool(); - int valueRange = provider.ConsumeIntegralInRange(0, 100); - node[key] = valueStr; - node["integer"] = valueInt; - node["float"] = valueFloat; - node["boolean"] = valueBool; - node["range"] = valueRange; - fileInfo.Marshal(node); - fileInfo.Unmarshal(node); - debugInfo.Marshal(node); - debugInfo.Unmarshal(node); -} - bool OnRemoteRequestFuzz(FuzzedDataProvider &provider) { std::shared_ptr cloudServiceImpl = std::make_shared(); @@ -175,11 +93,6 @@ bool OnRemoteRequestFuzz(FuzzedDataProvider &provider) extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { FuzzedDataProvider provider(data, size); - OHOS::TestScreenManager(provider); - OHOS::SyncStrategiesFuzz(provider); - OHOS::SyncStrategiesFuzz001(provider); - OHOS::SyncStrategiesFuzz002(provider); - OHOS::StoreDebugInfoFuzz(provider); OHOS::OnRemoteRequestFuzz(provider); return 0; } \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn new file mode 100644 index 000000000..f3f603972 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn @@ -0,0 +1,65 @@ +# 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("SyncStrategiesFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/service/cloud", + "${data_service_path}/framework/include", + "${data_service_path}/service/common", + ] + + fuzz_config_file = + "${data_service_path}/service/test/fuzztest/syncstrategies_fuzzer" + + sources = [ "syncstrategies_fuzzer.cpp" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + "-fno-access-control", + ] + + deps = [ + "${data_service_path}/service/cloud:distributeddata_cloud", + "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/common:distributeddata_common", + "${data_service_path}/service/bootstrap:distributeddata_bootstrap", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/service/permission:distributeddata_permit", + ] + + external_deps = [ + "access_token:libaccesstoken_sdk", + "access_token:libtoken_setproc", + "access_token:libtokenid_sdk", + "c_utils:utils", + "hilog:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":SyncStrategiesFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/corpus/init b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/corpus/init new file mode 100644 index 000000000..7ade8a0fa --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/syncstrategies_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/service/test/fuzztest/syncstrategies_fuzzer/project.xml b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/project.xml new file mode 100644 index 000000000..a37a23b15 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/syncstrategies_fuzzer.cpp b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/syncstrategies_fuzzer.cpp new file mode 100644 index 000000000..a29c25be2 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/syncstrategies_fuzzer.cpp @@ -0,0 +1,78 @@ +/* + * 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 "syncstrategies_fuzzer.h" +#include "sync_strategies/network_sync_strategy.h" + +using namespace OHOS::DistributedData; +using namespace OHOS::CloudData; + +namespace OHOS { +void SyncStrategiesFuzz001(FuzzedDataProvider &provider) +{ + int32_t user = provider.ConsumeIntegral(); + std::string bundleName = provider.ConsumeRandomLengthString(); + NetworkSyncStrategy strategy; + StoreInfo storeInfo; + storeInfo.user = user; + storeInfo.bundleName = bundleName; + strategy.CheckSyncAction(storeInfo); +} + +void SyncStrategiesFuzz002(FuzzedDataProvider &provider) +{ + uint32_t strategy = provider.ConsumeIntegral(); + NetworkSyncStrategy strategyInstance; + strategyInstance.Check(strategy); +} + +void SyncStrategiesFuzz003(FuzzedDataProvider &provider) +{ + int32_t user = provider.ConsumeIntegral(); + std::string bundleName = provider.ConsumeRandomLengthString(); + NetworkSyncStrategy strategyInstance; + strategyInstance.GetStrategy(user, bundleName); + strategyInstance.GetKey(user); + + NetworkSyncStrategy::StrategyInfo info; + info.user = 1; + info.bundleName = "StrategyInfo"; + Serializable::json node; + std::string key = provider.ConsumeRandomLengthString(); + std::string valueStr = provider.ConsumeRandomLengthString(); + int valueInt = provider.ConsumeIntegral(); + float valueFloat = provider.ConsumeFloatingPoint(); + bool valueBool = provider.ConsumeBool(); + int valueRange = provider.ConsumeIntegralInRange(0, 100); + node[key] = valueStr; + node["integer"] = valueInt; + node["float"] = valueFloat; + node["boolean"] = valueBool; + node["range"] = valueRange; + info.Marshal(node); + info.Unmarshal(node); +} +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::SyncStrategiesFuzz001(provider); + OHOS::SyncStrategiesFuzz002(provider); + OHOS::SyncStrategiesFuzz003(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/syncstrategies_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/syncstrategies_fuzzer.h new file mode 100644 index 000000000..abe3fcd00 --- /dev/null +++ b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/syncstrategies_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 SYNCSTRATEGIES_FUZZER_H + #define SYNCSTRATEGIES_FUZZER_H + + #define FUZZ_PROJECT_NAME "syncstrategies_fuzzer" + + #endif // SYNCSTRATEGIES_FUZZER_H \ No newline at end of file -- Gitee From 312f63cdbed489a72b55b05fd8556ac7632c3236 Mon Sep 17 00:00:00 2001 From: gecheng Date: Mon, 9 Jun 2025 21:39:30 +0800 Subject: [PATCH 05/10] =?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: gecheng --- services/distributeddataservice/service/test/fuzztest/BUILD.gn | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributeddataservice/service/test/fuzztest/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/BUILD.gn index c8ed8a7fb..f444f810b 100644 --- a/services/distributeddataservice/service/test/fuzztest/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/BUILD.gn @@ -23,7 +23,7 @@ group("fuzztest") { if (datamgr_service_cloud) { deps += [ "cloudservicestub_fuzzer:fuzztest", - "syncstrategies_fuzzer", + "syncstrategies_fuzzer:fuzztest", ] } -- Gitee From b95a5717c9b50b9aad63b2d97e911594ea0a459b Mon Sep 17 00:00:00 2001 From: gecheng Date: Mon, 9 Jun 2025 21:45:46 +0800 Subject: [PATCH 06/10] =?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: gecheng --- .../syncstrategies_fuzzer/syncstrategies_fuzzer.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/syncstrategies_fuzzer.h b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/syncstrategies_fuzzer.h index abe3fcd00..ab2199aa1 100644 --- a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/syncstrategies_fuzzer.h +++ b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/syncstrategies_fuzzer.h @@ -13,9 +13,9 @@ * limitations under the License. */ - #ifndef SYNCSTRATEGIES_FUZZER_H - #define SYNCSTRATEGIES_FUZZER_H +#ifndef SYNCSTRATEGIES_FUZZER_H +#define SYNCSTRATEGIES_FUZZER_H - #define FUZZ_PROJECT_NAME "syncstrategies_fuzzer" +#define FUZZ_PROJECT_NAME "syncstrategies_fuzzer" - #endif // SYNCSTRATEGIES_FUZZER_H \ No newline at end of file +#endif // SYNCSTRATEGIES_FUZZER_H \ No newline at end of file -- Gitee From ced3803b6a7c29ecde95ae84f34822d9ddcd85a2 Mon Sep 17 00:00:00 2001 From: gecheng Date: Mon, 9 Jun 2025 22:22:22 +0800 Subject: [PATCH 07/10] =?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: gecheng --- .../service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn index f3f603972..d4da3ff44 100644 --- a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn @@ -39,11 +39,12 @@ ohos_fuzztest("SyncStrategiesFuzzTest") { ] deps = [ - "${data_service_path}/service/cloud:distributeddata_cloud", + "${data_service_path}/adapter/dfx:distributeddata_dfx", + "${data_service_path}/adapter/utils:distributeddata_utils", "${data_service_path}/framework:distributeddatasvcfwk", + "${data_service_path}/service/cloud:distributeddata_cloud", "${data_service_path}/service/common:distributeddata_common", "${data_service_path}/service/bootstrap:distributeddata_bootstrap", - "${data_service_path}/adapter/dfx:distributeddata_dfx", "${data_service_path}/service/permission:distributeddata_permit", ] -- Gitee From 78ed21b3bb4741ecc41067ff7fe50b2532d7153f Mon Sep 17 00:00:00 2001 From: gecheng Date: Mon, 9 Jun 2025 23:02:51 +0800 Subject: [PATCH 08/10] =?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: gecheng --- .../service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn index d4da3ff44..fcc9489e4 100644 --- a/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn +++ b/services/distributeddataservice/service/test/fuzztest/syncstrategies_fuzzer/BUILD.gn @@ -20,8 +20,8 @@ ohos_fuzztest("SyncStrategiesFuzzTest") { module_out_path = "datamgr_service/datamgr_service" include_dirs = [ - "${data_service_path}/service/cloud", "${data_service_path}/framework/include", + "${data_service_path}/service/cloud", "${data_service_path}/service/common", ] @@ -40,7 +40,6 @@ ohos_fuzztest("SyncStrategiesFuzzTest") { deps = [ "${data_service_path}/adapter/dfx:distributeddata_dfx", - "${data_service_path}/adapter/utils:distributeddata_utils", "${data_service_path}/framework:distributeddatasvcfwk", "${data_service_path}/service/cloud:distributeddata_cloud", "${data_service_path}/service/common:distributeddata_common", @@ -54,6 +53,7 @@ ohos_fuzztest("SyncStrategiesFuzzTest") { "access_token:libtokenid_sdk", "c_utils:utils", "hilog:libhilog", + "kv_store:datamgr_common", ] } -- Gitee From 9a9b8373b265e47050ffe09b3e20fae55138cff9 Mon Sep 17 00:00:00 2001 From: gecheng Date: Tue, 10 Jun 2025 16:31:12 +0800 Subject: [PATCH 09/10] =?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: gecheng --- .../framework/test/fuzztest/BUILD.gn | 5 +- .../fuzztest/screenmanager_fuzzer/BUILD.gn | 55 +++++++++++++++++++ .../fuzztest/screenmanager_fuzzer/corpus/init | 16 ++++++ .../fuzztest/screenmanager_fuzzer/project.xml | 25 +++++++++ .../screenmanager_fuzzer.cpp | 40 ++++++++++++++ .../screenmanager_fuzzer.h | 21 +++++++ .../storedebuginfo_fuzzer.cpp | 10 ---- 7 files changed, 161 insertions(+), 11 deletions(-) create mode 100644 services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/BUILD.gn create mode 100644 services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/corpus/init create mode 100644 services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/project.xml create mode 100644 services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp create mode 100644 services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.h diff --git a/services/distributeddataservice/framework/test/fuzztest/BUILD.gn b/services/distributeddataservice/framework/test/fuzztest/BUILD.gn index 2a8920793..fdf9b461e 100644 --- a/services/distributeddataservice/framework/test/fuzztest/BUILD.gn +++ b/services/distributeddataservice/framework/test/fuzztest/BUILD.gn @@ -18,6 +18,9 @@ import("//foundation/distributeddatamgr/datamgr_service/datamgr_service.gni") group("fuzztest") { testonly = true - deps = [ "storedebuginfo_fuzzer:fuzztest" ] + deps = [ + "storedebuginfo_fuzzer:fuzztest", + "screenmanager_fuzzer:fuzztest" + ] } \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/BUILD.gn b/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/BUILD.gn new file mode 100644 index 000000000..f063faa15 --- /dev/null +++ b/services/distributeddataservice/framework/test/fuzztest/screenmanager_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("ScreenManagerFuzzTest") { + module_out_path = "datamgr_service/datamgr_service" + + include_dirs = [ + "${data_service_path}/framework/include", + ] + + fuzz_config_file = + "${data_service_path}/framework/test/fuzztest/screenmanager_fuzzer" + + sources = [ "screenmanager_fuzzer.cpp" ] + + cflags = [ + "-g", + "-O0", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + deps = [ + "${data_service_path}/framework:distributeddatasvcfwk", + ] + + external_deps = [ + "c_utils:utils", + "hilog:libhilog", + "kv_store:datamgr_common", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":ScreenManagerFuzzTest" ] +} +############################################################################### \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/corpus/init b/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/corpus/init new file mode 100644 index 000000000..7ade8a0fa --- /dev/null +++ b/services/distributeddataservice/framework/test/fuzztest/screenmanager_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/framework/test/fuzztest/screenmanager_fuzzer/project.xml b/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/project.xml new file mode 100644 index 000000000..a37a23b15 --- /dev/null +++ b/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp b/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp new file mode 100644 index 000000000..0377b177b --- /dev/null +++ b/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp @@ -0,0 +1,40 @@ +/* + * 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 "screenmanager_fuzzer.h" +#include "screen/screen_manager.h" + +using namespace OHOS::DistributedData; + +namespace OHOS { +void TestScreenManager(FuzzedDataProvider &provider) +{ + ScreenManager::GetInstance()->Subscribe(nullptr); + ScreenManager::GetInstance()->Unsubscribe(nullptr); + ScreenManager::GetInstance()->BindExecutor(nullptr); + ScreenManager::GetInstance()->SubscribeScreenEvent(); + ScreenManager::GetInstance()->UnsubscribeScreenEvent(); +} + +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + FuzzedDataProvider provider(data, size); + OHOS::TestScreenManager(provider); + return 0; +} \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.h b/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.h new file mode 100644 index 000000000..3f47a8ee2 --- /dev/null +++ b/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_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 SCREENMANAGER_FUZZER_H +#define SCREENMANAGER_FUZZER_H + +#define FUZZ_PROJECT_NAME "screenmanager_fuzzer" + +#endif // SCREENMANAGER_FUZZER_H diff --git a/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/storedebuginfo_fuzzer.cpp b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/storedebuginfo_fuzzer.cpp index a3dd18a2d..f497a3d16 100644 --- a/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/storedebuginfo_fuzzer.cpp +++ b/services/distributeddataservice/framework/test/fuzztest/storedebuginfo_fuzzer/storedebuginfo_fuzzer.cpp @@ -15,20 +15,11 @@ #include #include "storedebuginfo_fuzzer.h" -#include "screen/screen_manager.h" #include "metadata/store_debug_info.h" using namespace OHOS::DistributedData; namespace OHOS { -void TestScreenManager(FuzzedDataProvider &provider) -{ - ScreenManager::GetInstance()->Subscribe(nullptr); - ScreenManager::GetInstance()->Unsubscribe(nullptr); - ScreenManager::GetInstance()->BindExecutor(nullptr); - ScreenManager::GetInstance()->SubscribeScreenEvent(); - ScreenManager::GetInstance()->UnsubscribeScreenEvent(); -} void StoreDebugInfoFuzz(FuzzedDataProvider &provider) { @@ -59,7 +50,6 @@ void StoreDebugInfoFuzz(FuzzedDataProvider &provider) extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { FuzzedDataProvider provider(data, size); - OHOS::TestScreenManager(provider); OHOS::StoreDebugInfoFuzz(provider); return 0; } \ No newline at end of file -- Gitee From cc51eba801822ed7d1ca309d2a5316ead1a452ba Mon Sep 17 00:00:00 2001 From: gecheng Date: Tue, 10 Jun 2025 16:35:50 +0800 Subject: [PATCH 10/10] =?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: gecheng --- .../distributeddataservice/framework/test/fuzztest/BUILD.gn | 3 +-- .../fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp | 6 +++--- .../fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.h | 4 ++-- 3 files changed, 6 insertions(+), 7 deletions(-) diff --git a/services/distributeddataservice/framework/test/fuzztest/BUILD.gn b/services/distributeddataservice/framework/test/fuzztest/BUILD.gn index fdf9b461e..b35cb67af 100644 --- a/services/distributeddataservice/framework/test/fuzztest/BUILD.gn +++ b/services/distributeddataservice/framework/test/fuzztest/BUILD.gn @@ -20,7 +20,6 @@ group("fuzztest") { deps = [ "storedebuginfo_fuzzer:fuzztest", - "screenmanager_fuzzer:fuzztest" + "screenmanager_fuzzer:fuzztest", ] - } \ No newline at end of file diff --git a/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp b/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp index 0377b177b..d944f95c3 100644 --- a/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp +++ b/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.cpp @@ -18,7 +18,7 @@ #include "screen/screen_manager.h" using namespace OHOS::DistributedData; - + namespace OHOS { void TestScreenManager(FuzzedDataProvider &provider) { @@ -28,9 +28,9 @@ void TestScreenManager(FuzzedDataProvider &provider) ScreenManager::GetInstance()->SubscribeScreenEvent(); ScreenManager::GetInstance()->UnsubscribeScreenEvent(); } - + } // namespace OHOS - + /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { diff --git a/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.h b/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.h index 3f47a8ee2..ab2fe6fe3 100644 --- a/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.h +++ b/services/distributeddataservice/framework/test/fuzztest/screenmanager_fuzzer/screenmanager_fuzzer.h @@ -15,7 +15,7 @@ #ifndef SCREENMANAGER_FUZZER_H #define SCREENMANAGER_FUZZER_H - + #define FUZZ_PROJECT_NAME "screenmanager_fuzzer" - + #endif // SCREENMANAGER_FUZZER_H -- Gitee