From 34b781c6e9eec3b3a6fe9f02cdf8edbf6a1c2c4a Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Sun, 27 Apr 2025 09:15:34 +0000 Subject: [PATCH 01/10] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20devicenamemanagerone?= =?UTF-8?q?=5Ffuzzer?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/servicesfuzztest/devicenamemanagerone_fuzzer/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/servicesfuzztest/devicenamemanagerone_fuzzer/.keep diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/.keep b/test/servicesfuzztest/devicenamemanagerone_fuzzer/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From fda580afc9f0d9712317cc1295efcc8b2b69ee45 Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Sun, 27 Apr 2025 09:28:18 +0000 Subject: [PATCH 02/10] =?UTF-8?q?=E6=96=B0=E5=BB=BA=20corpus?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/.keep diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/.keep b/test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/.keep new file mode 100644 index 000000000..e69de29bb -- Gitee From 295b61e1438896a59624963872d5f9fced3f4caf Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Sun, 27 Apr 2025 09:29:06 +0000 Subject: [PATCH 03/10] add test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/init. Signed-off-by: wzhhhh --- .../devicenamemanagerone_fuzzer/corpus/init | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/init diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/init b/test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/init new file mode 100644 index 000000000..c5f10bf72 --- /dev/null +++ b/test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# Copyright (c) 2020-2021 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 -- Gitee From 639c7deffd2921b29bc450db07c889ab1ec18462 Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Sun, 27 Apr 2025 09:29:35 +0000 Subject: [PATCH 04/10] add test/servicesfuzztest/devicenamemanagerone_fuzzer/BUILD.gn. Signed-off-by: wzhhhh --- .../devicenamemanagerone_fuzzer/BUILD.gn | 93 +++++++++++++++++++ 1 file changed, 93 insertions(+) create mode 100644 test/servicesfuzztest/devicenamemanagerone_fuzzer/BUILD.gn diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/BUILD.gn b/test/servicesfuzztest/devicenamemanagerone_fuzzer/BUILD.gn new file mode 100644 index 000000000..4de76326b --- /dev/null +++ b/test/servicesfuzztest/devicenamemanagerone_fuzzer/BUILD.gn @@ -0,0 +1,93 @@ +# 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/distributedhardware/device_manager/device_manager.gni") + +##############################fuzztest########################################## +ohos_fuzztest("DeviceNameManagerOneFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/servicesfuzztest/devicenamemanagerone_fuzzer" + + include_dirs = [ + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${servicesimpl_path}/include", + "${servicesimpl_path}/include/dependency/timer", + "${servicesimpl_path}/include/discovery", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/authentication", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/ipc/standard", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/deviceinfo/", + "${servicesimpl_path}/include/devicestate", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/config", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ "device_name_manager_one_fuzzer.cpp" ] + + deps = [ + "${devicemanager_path}/services/service:devicemanagerservicetest", + "${utils_path}:devicemanagerutilstest", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DeviceNameManagerOneFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] + + external_deps = [ + "ability_base:want", + "cJSON:cjson", + "data_share:datashare_common", + "data_share:datashare_consumer", + "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + "dsoftbus:softbus_client", + "ffrt:libffrt", + "hilog:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DeviceNameManagerOneFuzzTest" ] +} +############################################################################### -- Gitee From 626a5b2bf560ac7a9cd5780e08cbf07f4c8d8127 Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Sun, 27 Apr 2025 09:29:59 +0000 Subject: [PATCH 05/10] add test/servicesfuzztest/devicenamemanagerone_fuzzer/device_name_manager_one_fuzzer.cpp. Signed-off-by: wzhhhh --- .../device_name_manager_one_fuzzer.cpp | 111 ++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 test/servicesfuzztest/devicenamemanagerone_fuzzer/device_name_manager_one_fuzzer.cpp diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/device_name_manager_one_fuzzer.cpp b/test/servicesfuzztest/devicenamemanagerone_fuzzer/device_name_manager_one_fuzzer.cpp new file mode 100644 index 000000000..2d65e4fa4 --- /dev/null +++ b/test/servicesfuzztest/devicenamemanagerone_fuzzer/device_name_manager_one_fuzzer.cpp @@ -0,0 +1,111 @@ +/* + * 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 +#include +#include "device_name_manager.h" +#include "device_name_manager_one_fuzzer.h" + +namespace OHOS { +namespace DistributedHardware { +void DeviceNameManagerOnePrivateFuzzTest(FuzzedDataProvider &fdp) +{ + int32_t userId = fdp.ConsumeIntegral(); + int32_t maxNamelength = fdp.ConsumeIntegral(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::string prefix = fdp.ConsumeRandomLengthString(); + std::string suffix = fdp.ConsumeRandomLengthString(); + std::string state = fdp.ConsumeRandomLengthString(); + std::string tableName = fdp.ConsumeRandomLengthString(); + std::string key = fdp.ConsumeRandomLengthString(); + std::string proxyUri = fdp.ConsumeRemainingBytesAsString(); + std::string value; + + DeviceNameManager::GetInstance().RegisterDeviceNameChangeMonitor(fdp.ConsumeIntegral(), + fdp.ConsumeIntegral()); + DeviceNameManager::GetInstance().UnRegisterDeviceNameChangeMonitor(userId); + DeviceNameManager::GetInstance().InitDeviceName(userId); + DeviceNameManager::GetInstance().InitDeviceNameToSoftBus(prefix, suffix); + DeviceNameManager::GetInstance().GetLocalDisplayDeviceName( + prefix, suffix, maxNamelength); + DeviceNameManager::GetInstance().SubstrByBytes(fdp.ConsumeRandomLengthString(), + fdp.ConsumeIntegral()); + DeviceNameManager::GetInstance().GetSystemLanguage(); + DeviceNameManager::GetInstance().GetSystemRegion(); + DeviceNameManager::GetInstance().GetLocalMarketName(); + DeviceNameManager::GetInstance().InitDisplayDeviceNameToSettingsData(fdp.ConsumeRandomLengthString(), + fdp.ConsumeRandomLengthString(), userId); + DeviceNameManager::GetInstance().GetUserDefinedDeviceName(userId, deviceName); + DeviceNameManager::GetInstance().SetUserDefinedDeviceName(fdp.ConsumeRandomLengthString(), userId); + DeviceNameManager::GetInstance().GetDisplayDeviceName(userId, deviceName); + DeviceNameManager::GetInstance().SetDisplayDeviceName(fdp.ConsumeRandomLengthString(), userId); + DeviceNameManager::GetInstance().SetDisplayDeviceNameState(state, userId); + DeviceNameManager::GetInstance().GetDeviceName(deviceName); + DeviceNameManager::GetInstance().SetDeviceName(fdp.ConsumeRandomLengthString()); + DeviceNameManager::GetInstance().GetValue(tableName, userId, key,value); + DeviceNameManager::GetInstance().SetValue(tableName, userId, key, fdp.ConsumeRandomLengthString()); + DeviceNameManager::GetInstance().GetProxyUriStr(tableName, userId); + auto helper = DeviceNameManager::GetInstance().CreateDataShareHelper(proxyUri); + DeviceNameManager::GetInstance().MakeUri(proxyUri, key); + DeviceNameManager::GetInstance().ReleaseDataShareHelper(helper); +} + +void DeviceNameManagerOneFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr) { + return; + } + FuzzedDataProvider fdp(data, size); + + int32_t userId = fdp.ConsumeIntegral(); + int32_t maxNamelength = fdp.ConsumeIntegral(); + std::string displayName; + std::string deviceName = fdp.ConsumeRandomLengthString(); + int32_t curUserId = fdp.ConsumeIntegral(); + int32_t preUserId = fdp.ConsumeIntegral(); + std::string prefix = fdp.ConsumeRandomLengthString(); + std::string suffix = fdp.ConsumeRandomLengthString(); + std::string state = fdp.ConsumeRandomLengthString(); + std::string tableName = fdp.ConsumeRandomLengthString(); + std::string key = fdp.ConsumeRandomLengthString(); + std::string proxyUri = fdp.ConsumeRemainingBytesAsString(); + + DeviceNameManager::GetInstance().AccountSysReady(userId); + DeviceNameManager::GetInstance().DataShareReady(); + DeviceNameManager::GetInstance().InitDeviceNameWhenSoftBusReady(); + DeviceNameManager::GetInstance().GetLocalDisplayDeviceName(maxNamelength, displayName); + DeviceNameManager::GetInstance().ModifyUserDefinedName(deviceName); + DeviceNameManager::GetInstance().RestoreLocalDeviceName(); + DeviceNameManager::GetInstance().InitDeviceNameWhenUserSwitch(curUserId, preUserId); + DeviceNameManager::GetInstance().InitDeviceNameWhenNameChange(userId); + DeviceNameManager::GetInstance().InitDeviceNameWhenLogout(); + DeviceNameManager::GetInstance().InitDeviceNameWhenLogin(); + DeviceNameManager::GetInstance().InitDeviceNameWhenNickChange(); + DeviceNameManager::GetInstance().InitDeviceNameWhenLanguageOrRegionChanged(); + + OHOS::DistributedHardware::DeviceNameManagerOnePrivateFuzzTest(fdp); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DeviceNameManagerOneFuzzTest(data, size); + + return 0; +} -- Gitee From cab33a101488022a8defd96ecdafdb591d2aa556 Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Sun, 27 Apr 2025 09:30:29 +0000 Subject: [PATCH 06/10] add test/servicesfuzztest/devicenamemanagerone_fuzzer/device_name_manager_one_fuzzer.h. Signed-off-by: wzhhhh --- .../device_name_manager_one_fuzzer.h | 21 +++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 test/servicesfuzztest/devicenamemanagerone_fuzzer/device_name_manager_one_fuzzer.h diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/device_name_manager_one_fuzzer.h b/test/servicesfuzztest/devicenamemanagerone_fuzzer/device_name_manager_one_fuzzer.h new file mode 100644 index 000000000..ab70ba675 --- /dev/null +++ b/test/servicesfuzztest/devicenamemanagerone_fuzzer/device_name_manager_one_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 DP_ACL_ADD_FUZZER_H +#define DP_ACL_ADD_FUZZER_H + +#define FUZZ_PROJECT_NAME "dpacladd_fuzzer" + +#endif // DP_ACL_ADD_FUZZER_H -- Gitee From f571e001679a2f0f4536a4a1e471518e80a93dc0 Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Sun, 27 Apr 2025 09:30:58 +0000 Subject: [PATCH 07/10] add test/servicesfuzztest/devicenamemanagerone_fuzzer/project.xml. Signed-off-by: wzhhhh --- .../devicenamemanagerone_fuzzer/project.xml | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 test/servicesfuzztest/devicenamemanagerone_fuzzer/project.xml diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/project.xml b/test/servicesfuzztest/devicenamemanagerone_fuzzer/project.xml new file mode 100644 index 000000000..afd90798d --- /dev/null +++ b/test/servicesfuzztest/devicenamemanagerone_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file -- Gitee From 5c02ea1b23500ba9a8f45d3cacbe73ba0978a5db Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Sun, 27 Apr 2025 09:31:11 +0000 Subject: [PATCH 08/10] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/servicesfuzztest/devicenamemanagerone=5Ffuzzer/.keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/servicesfuzztest/devicenamemanagerone_fuzzer/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/servicesfuzztest/devicenamemanagerone_fuzzer/.keep diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/.keep b/test/servicesfuzztest/devicenamemanagerone_fuzzer/.keep deleted file mode 100644 index e69de29bb..000000000 -- Gitee From 91954478f69508aa571f5699d59f9d7e68af58f7 Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Sun, 27 Apr 2025 09:31:48 +0000 Subject: [PATCH 09/10] =?UTF-8?q?=E5=88=A0=E9=99=A4=E6=96=87=E4=BB=B6=20te?= =?UTF-8?q?st/servicesfuzztest/devicenamemanagerone=5Ffuzzer/corpus/.keep?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/.keep | 0 1 file changed, 0 insertions(+), 0 deletions(-) delete mode 100644 test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/.keep diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/.keep b/test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/.keep deleted file mode 100644 index e69de29bb..000000000 -- Gitee From 6587656326e8f559e49d3f77416ecbd5075c7987 Mon Sep 17 00:00:00 2001 From: wzhhhh Date: Sun, 27 Apr 2025 09:33:06 +0000 Subject: [PATCH 10/10] update test/servicesfuzztest/BUILD.gn. Signed-off-by: wzhhhh --- test/servicesfuzztest/BUILD.gn | 1 + 1 file changed, 1 insertion(+) diff --git a/test/servicesfuzztest/BUILD.gn b/test/servicesfuzztest/BUILD.gn index 61dde20fd..078b76ddb 100644 --- a/test/servicesfuzztest/BUILD.gn +++ b/test/servicesfuzztest/BUILD.gn @@ -22,6 +22,7 @@ group("fuzztest") { "devicemanagernotify_fuzzer:fuzztest", "devicemanagerservice_fuzzer:fuzztest", "devicenamemanager_fuzzer:fuzztest", + "devicenamemanagerone_fuzzer:fuzztest", "deviceprofileconnector_fuzzer:fuzztest", "devicepublish_fuzzer:fuzztest", "dmcommtool_fuzzer:fuzztest", -- Gitee