diff --git a/test/servicesfuzztest/BUILD.gn b/test/servicesfuzztest/BUILD.gn index 61dde20fda50ad9e8d6b511bac8bb50e17ce28c1..078b76ddb7383508b03b48004ffc6cd0fbf6c747 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", diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/BUILD.gn b/test/servicesfuzztest/devicenamemanagerone_fuzzer/BUILD.gn new file mode 100644 index 0000000000000000000000000000000000000000..4de76326b3cf2ce128a7d845a8c0cbbefbc5f90b --- /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" ] +} +############################################################################### diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/init b/test/servicesfuzztest/devicenamemanagerone_fuzzer/corpus/init new file mode 100644 index 0000000000000000000000000000000000000000..c5f10bf72d43fc972162a945f0be33e02d4b2c7f --- /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 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 0000000000000000000000000000000000000000..2d65e4fa4bb566e1aa83844786d686fd9e36e141 --- /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; +} 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 0000000000000000000000000000000000000000..ab70ba675f642a96443d77786348bde76973334f --- /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 diff --git a/test/servicesfuzztest/devicenamemanagerone_fuzzer/project.xml b/test/servicesfuzztest/devicenamemanagerone_fuzzer/project.xml new file mode 100644 index 0000000000000000000000000000000000000000..afd90798db45dd3853b00cf9c476ad4b245107e1 --- /dev/null +++ b/test/servicesfuzztest/devicenamemanagerone_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file