From 77e9a370af002118abeb42dee3bcf3532607da93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Sun, 22 Jun 2025 18:40:35 +0800 Subject: [PATCH 1/7] add FUZZ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- test/BUILD.gn | 1 + test/commonfuzztest/BUILD.gn | 1 + .../dmnegotiateprocess_fuzzer/BUILD.gn | 80 ++++++++++++ .../dmnegotiateprocess_fuzzer/corpus/init | 13 ++ .../dm_negotiate_process_fuzzer.cpp | 79 ++++++++++++ .../dm_negotiate_process_fuzzer.h | 21 ++++ .../dmnegotiateprocess_fuzzer/project.xml | 25 ++++ test/jsonfuzztest/BUILD.gn | 20 +++ .../jsonobjectnlohmannjson_fuzzer/BUILD.gn | 63 ++++++++++ .../jsonobjectnlohmannjson_fuzzer/corpus/init | 13 ++ .../json_object_nlohmannjson_fuzzer.cpp | 70 +++++++++++ .../json_object_nlohmannjson_fuzzer.h | 21 ++++ .../jsonobjectnlohmannjson_fuzzer/project.xml | 25 ++++ .../devicenamemanager_fuzzer/BUILD.gn | 2 +- .../device_name_manager_fuzzer.cpp | 31 ++++- .../dm_transport_fuzzer.cpp | 39 +++--- .../softbus_connector_fuzzer.cpp | 101 ++++++++++++++- .../softbuslistener_fuzzer/project.xml | 2 +- .../softbus_listener_fuzzer.cpp | 115 +++++++++++++++++- 19 files changed, 693 insertions(+), 29 deletions(-) create mode 100644 test/commonfuzztest/dmnegotiateprocess_fuzzer/BUILD.gn create mode 100644 test/commonfuzztest/dmnegotiateprocess_fuzzer/corpus/init create mode 100644 test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp create mode 100644 test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.h create mode 100644 test/commonfuzztest/dmnegotiateprocess_fuzzer/project.xml create mode 100644 test/jsonfuzztest/BUILD.gn create mode 100644 test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/BUILD.gn create mode 100644 test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/corpus/init create mode 100644 test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.cpp create mode 100644 test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.h create mode 100644 test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/project.xml diff --git a/test/BUILD.gn b/test/BUILD.gn index c856a29d0..f756c7a5e 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -20,6 +20,7 @@ group("test") { "benchmarktest:benchmarktest", "commonfuzztest:fuzztest", "interfacesfuzztest:fuzztest", + "jsonfuzztest:fuzztest", "servicesfuzztest:fuzztest", "softbusfuzztest:fuzztest", "unittest:unittest", diff --git a/test/commonfuzztest/BUILD.gn b/test/commonfuzztest/BUILD.gn index c88c67ba2..617816463 100644 --- a/test/commonfuzztest/BUILD.gn +++ b/test/commonfuzztest/BUILD.gn @@ -22,6 +22,7 @@ group("fuzztest") { "dmauthmanagerv2_fuzzer:fuzztest", "dmcommoneventmanager_fuzzer:fuzztest", "dmcredentialimpl_fuzzer:fuzztest", + "dmnegotiateprocess_fuzzer:fuzztest", "generateencrypteduuid_fuzzer:fuzztest", "getdeviceinfo_fuzzer:fuzztest", "hichainconnector_fuzzer:fuzztest", diff --git a/test/commonfuzztest/dmnegotiateprocess_fuzzer/BUILD.gn b/test/commonfuzztest/dmnegotiateprocess_fuzzer/BUILD.gn new file mode 100644 index 000000000..1ce9887cd --- /dev/null +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("DmNegotiateProcessFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/commonfuzztest/dmnegotiateprocess_fuzzer" + + include_dirs = [ + "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/authentication_v2", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/dependency/timer", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dm_negotiate_process_fuzzer.cpp" ] + + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${services_path}:devicemanagerservicetest", + "${servicesimpl_path}:devicemanagerserviceimpl", + "${utils_path}:devicemanagerutilstest", + ] + + external_deps = [ + "cJSON:cjson", + "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", + "init:libbegetutil", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DmNegotiateProcessFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DmNegotiateProcessFuzzTest" ] +} +############################################################################### diff --git a/test/commonfuzztest/dmnegotiateprocess_fuzzer/corpus/init b/test/commonfuzztest/dmnegotiateprocess_fuzzer/corpus/init new file mode 100644 index 000000000..8f37f0925 --- /dev/null +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp new file mode 100644 index 000000000..682875a33 --- /dev/null +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.cpp @@ -0,0 +1,79 @@ +/* + * Copyright (c) 2025-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 "dm_negotiate_process_fuzzer.h" + +#include +#include + +#include "device_manager_service_listener.h" +#include "dm_negotiate_process.h" + +namespace OHOS { +namespace DistributedHardware { + +void DmNegotiateProcessFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + std::shared_ptr context = std::make_shared(); + NoCredNoAclImportAuthType noCredNoAclImportAuthType; + noCredNoAclImportAuthType.NegotiateHandle(context); + NoCredNoAclInputAuthType noCredNoAclInputAuthType; + noCredNoAclInputAuthType.NegotiateHandle(context); + IdentCredNoAclImportAuthType identCredNoAclImportAuthType; + identCredNoAclImportAuthType.NegotiateHandle(context); + IdentCredNoAclInputAuthType identCredNoAclInputAuthType; + identCredNoAclInputAuthType.NegotiateHandle(context); + IdentCredIdentAclImportAuthType identCredIdentAclImportAuthType; + identCredIdentAclImportAuthType.NegotiateHandle(context); + IdentCredIdentAclInputAuthType identCredIdentAclInputAuthType; + identCredIdentAclInputAuthType.NegotiateHandle(context); + IdentCredP2pAclImportAuthType identCredP2pAclImportAuthType; + identCredP2pAclImportAuthType.NegotiateHandle(context); + IdentCredP2pAclInputAuthType identCredP2pAclInputAuthType; + identCredP2pAclInputAuthType.NegotiateHandle(context); + ShareCredNoAclImportAuthType shareCredNoAclImportAuthType; + shareCredNoAclImportAuthType.NegotiateHandle(context); + ShareCredNoAclInputAuthType shareCredNoAclInputAuthType; + shareCredNoAclInputAuthType.NegotiateHandle(context); + ShareCredShareAclImportAuthType shareCredShareAclImportAuthType; + shareCredShareAclImportAuthType.NegotiateHandle(context); + ShareCredShareAclInputAuthType shareCredShareAclInputAuthType; + shareCredShareAclInputAuthType.NegotiateHandle(context); + ShareCredP2pAclImportAuthType shareCredP2pAclImportAuthType; + shareCredP2pAclImportAuthType.NegotiateHandle(context); + ShareCredP2pAclInputAuthType shareCredP2pAclInputAuthType; + shareCredP2pAclInputAuthType.NegotiateHandle(context); + P2pCredNoAclImportAuthType p2pCredNoAclImportAuthType; + p2pCredNoAclImportAuthType.NegotiateHandle(context); + P2pCredNoAclInputAuthType p2pCredNoAclInputAuthType; + p2pCredNoAclInputAuthType.NegotiateHandle(context); + P2pCredP2pAclImportAuthType p2pCredP2pAclImportAuthType; + p2pCredP2pAclImportAuthType.NegotiateHandle(context); + P2pCredP2pAclInputAuthType p2pCredP2pAclInputAuthType; + p2pCredP2pAclInputAuthType.NegotiateHandle(context); +} +} // namespace DistributedHardware +} // namespace OHOS + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DmNegotiateProcessFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.h b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_fuzzer.h new file mode 100644 index 000000000..e79352fb8 --- /dev/null +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/dm_negotiate_process_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 DM_NEGOTIATE_PROCESS_FUZZER_H +#define DM_NEGOTIATE_PROCESS_FUZZER_H + +#define FUZZ_PROJECT_NAME "dmnegotiateprocess_fuzzer" + +#endif // DM_NEGOTIATE_PROCESS_FUZZER_H \ No newline at end of file diff --git a/test/commonfuzztest/dmnegotiateprocess_fuzzer/project.xml b/test/commonfuzztest/dmnegotiateprocess_fuzzer/project.xml new file mode 100644 index 000000000..500f6f414 --- /dev/null +++ b/test/commonfuzztest/dmnegotiateprocess_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/jsonfuzztest/BUILD.gn b/test/jsonfuzztest/BUILD.gn new file mode 100644 index 000000000..bb5efd0aa --- /dev/null +++ b/test/jsonfuzztest/BUILD.gn @@ -0,0 +1,20 @@ +# 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. + +group("fuzztest") { + testonly = true + + deps = [ + "jsonobjectnlohmannjson_fuzzer:fuzztest", + ] +} diff --git a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/BUILD.gn b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/BUILD.gn new file mode 100644 index 000000000..e90d83b3b --- /dev/null +++ b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/BUILD.gn @@ -0,0 +1,63 @@ +# 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("JsonObjectNlohmannjsonFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = "${devicemanager_path}/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer" + + include_dirs = [ + "${common_path}/include", + "${json_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "json_object_nlohmannjson_fuzzer.cpp", + "${json_path}/src/json_object_cjson.cpp", ] + + deps = [] + + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "hilog:libhilog", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"JsonObjectNlohmannjsonFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":JsonObjectNlohmannjsonFuzzTest" ] +} +############################################################################### diff --git a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/corpus/init b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/corpus/init new file mode 100644 index 000000000..8f37f0925 --- /dev/null +++ b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.cpp b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.cpp new file mode 100644 index 000000000..dbb463c0a --- /dev/null +++ b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.cpp @@ -0,0 +1,70 @@ +/* + * 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 "json_object_nlohmannjson_fuzzer.h" + +#include +#include +#include +#include + +#include "dm_constants.h" +#include "json_object.h" +namespace OHOS { +namespace DistributedHardware { + +void JsonObjectNlohmannjsonFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + JsonItemObject itemObject; + JsonItemObject itemObjectNew; + itemObject["key1"] = fdp.ConsumeIntegral(); + std::string str_value = fdp.ConsumeRandomLengthString(); + int16_t int16_value = fdp.ConsumeIntegral(); + double double_value = fdp.ConsumeFloatingPoint(); + bool bool_value = fdp.ConsumeBool(); + uint8_t uint8_value = fdp.ConsumeIntegral(); + uint16_t uint16_value = fdp.ConsumeIntegral(); + uint32_t uint32_value = fdp.ConsumeIntegral(); + int64_t int64_value = fdp.ConsumeIntegral(); + ToJson(itemObject, double_value); + ToJson(itemObject, int16_value); + FromJson(itemObject, double_value); + FromJson(itemObject, bool_value); + FromJson(itemObject, uint8_value); + FromJson(itemObject, uint16_value); + itemObject.IsNumber(); + itemObjectNew = itemObject; + itemObjectNew.PushBack(str_value); + itemObjectNew.PushBack(double_value); + itemObjectNew.PushBack(int64_value); + itemObjectNew.GetTo(double_value); + itemObjectNew.GetTo(uint32_value); + itemObjectNew.GetTo(bool_value); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::JsonObjectNlohmannjsonFuzzTest(data, size); + + return 0; +} diff --git a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.h b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.h new file mode 100644 index 000000000..f01aa3031 --- /dev/null +++ b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_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 JSON_OBJECT_NLOHMANNJSON_FUZZER_H +#define JSON_OBJECT_NLOHMANNJSON_FUZZER_H + +#define FUZZ_PROJECT_NAME "jsonobjectnlohmannjson_fuzzer" + +#endif // JSON_OBJECT_NLOHMANNJSON_FUZZER_H \ No newline at end of file diff --git a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/project.xml b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/project.xml new file mode 100644 index 000000000..500f6f414 --- /dev/null +++ b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn b/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn index e769025ec..a129f111d 100644 --- a/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn +++ b/test/servicesfuzztest/devicenamemanager_fuzzer/BUILD.gn @@ -63,7 +63,7 @@ ohos_fuzztest("DeviceNameManagerFuzzTest") { deps = [ "${devicemanager_path}/services/service:devicemanagerservice", - "${utils_path}:devicemanagerutils", + "${utils_path}:devicemanagerutilstest", ] defines = [ diff --git a/test/servicesfuzztest/devicenamemanager_fuzzer/device_name_manager_fuzzer.cpp b/test/servicesfuzztest/devicenamemanager_fuzzer/device_name_manager_fuzzer.cpp index d10be1a5f..34c66b67c 100644 --- a/test/servicesfuzztest/devicenamemanager_fuzzer/device_name_manager_fuzzer.cpp +++ b/test/servicesfuzztest/devicenamemanager_fuzzer/device_name_manager_fuzzer.cpp @@ -13,24 +13,24 @@ * limitations under the License. */ +#include "device_name_manager_fuzzer.h" + #include #include +#include #include #include #include #include -#include -#include "device_name_manager_fuzzer.h" #include "device_name_manager.h" #include "dm_constants.h" - namespace OHOS { namespace DistributedHardware { namespace { - constexpr int32_t INT32_SIZE = 5; +constexpr int32_t INT32_SIZE = 5; } std::shared_ptr deviceNameMgr_ = std::make_shared(); @@ -105,8 +105,28 @@ void DeviceNameManagerFirstFuzzTest(const uint8_t* data, size_t size) std::shared_ptr helper = nullptr; deviceNameMgr_->ReleaseDataShareHelper(helper); } + +void DeviceNameManagerSecondFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::shared_ptr deviceNameMgr = std::make_shared(); + deviceNameMgr->UnInit(); + deviceNameMgr->GetUserDefinedDeviceName(); + std::string str; + deviceNameMgr->AnoyPrivacyString(str); + str = "1"; + deviceNameMgr->AnoyPrivacyString(str); + str = "1234"; + deviceNameMgr->AnoyPrivacyString(str); + str = fdp.ConsumeRandomLengthString(); + deviceNameMgr->AnoyPrivacyString(str); + deviceNameMgr->ConvertToWholeCharacter(str); } -} +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) @@ -114,5 +134,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ OHOS::DistributedHardware::DeviceNameManagerFuzzTest(data, size); OHOS::DistributedHardware::DeviceNameManagerFirstFuzzTest(data, size); + OHOS::DistributedHardware::DeviceNameManagerSecondFuzzTest(data, size); return 0; } diff --git a/test/servicesfuzztest/dmtransport_fuzzer/dm_transport_fuzzer.cpp b/test/servicesfuzztest/dmtransport_fuzzer/dm_transport_fuzzer.cpp index 684e60ddd..f01ed0edf 100644 --- a/test/servicesfuzztest/dmtransport_fuzzer/dm_transport_fuzzer.cpp +++ b/test/servicesfuzztest/dmtransport_fuzzer/dm_transport_fuzzer.cpp @@ -13,17 +13,17 @@ * limitations under the License. */ +#include "dm_transport_fuzzer.h" + #include #include +#include #include #include #include -#include -#include "dm_transport.h" -#include "dm_transport_fuzzer.h" #include "dm_comm_tool.h" - +#include "dm_transport.h" namespace OHOS { namespace DistributedHardware { @@ -31,7 +31,6 @@ namespace DistributedHardware { std::shared_ptr dmCommToolPtr_ = std::make_shared(); std::shared_ptr dmTransPortPtr_ = std::make_shared(dmCommToolPtr_); - void DmTransPortFuzzTest(const uint8_t* data, size_t size) { if ((data == nullptr) || (size < sizeof(int32_t))) { @@ -42,18 +41,16 @@ void DmTransPortFuzzTest(const uint8_t* data, size_t size) std::string rmtNetworkId(reinterpret_cast(data), size); std::string dmPkgName(reinterpret_cast(data), size); std::string peerSocketName(reinterpret_cast(data), size); - PeerSocketInfo info = { - .name = const_cast(peerSocketName.c_str()), + PeerSocketInfo info = { .name = const_cast(peerSocketName.c_str()), .networkId = const_cast(rmtNetworkId.c_str()), .pkgName = const_cast(dmPkgName.c_str()), - .dataType = DATA_TYPE_BYTES - }; + .dataType = DATA_TYPE_BYTES }; dmTransPortPtr_->OnSocketOpened(socketId, info); dmTransPortPtr_->OnSocketOpened(socketId, info); ShutdownReason reason = ShutdownReason::SHUTDOWN_REASON_LNN_CHANGED; dmTransPortPtr_->OnSocketClosed(socketId, reason); - void *dataInfo = nullptr; + void* dataInfo = nullptr; uint32_t dataLen = 0; dmTransPortPtr_->OnBytesReceived(socketId, dataInfo, dataLen); @@ -74,7 +71,7 @@ void DmTransPortFirstFuzzTest(const uint8_t* data, size_t size) if ((data == nullptr) || (size < sizeof(int32_t))) { return; } - + const char* jsonString = R"({ "MsgType": "0", "userId": "12345", @@ -95,12 +92,10 @@ void DmTransPortFirstFuzzTest(const uint8_t* data, size_t size) std::string rmtNetworkId(reinterpret_cast(data), size); std::string dmPkgName(reinterpret_cast(data), size); std::string peerSocketName(reinterpret_cast(data), size); - PeerSocketInfo info = { - .name = const_cast(peerSocketName.c_str()), + PeerSocketInfo info = { .name = const_cast(peerSocketName.c_str()), .networkId = const_cast(rmtNetworkId.c_str()), .pkgName = const_cast(dmPkgName.c_str()), - .dataType = DATA_TYPE_BYTES - }; + .dataType = DATA_TYPE_BYTES }; dmTransPortPtr_->OnSocketOpened(socketId, info); dmTransPortPtr_->HandleReceiveMessage(socketId, payload); dmTransPortPtr_->CreateClientSocket(rmtNetworkId); @@ -120,8 +115,19 @@ void DmTransPortFirstFuzzTest(const uint8_t* data, size_t size) std::string remoteDevId(reinterpret_cast(data), size); dmTransPortPtr_->ClearDeviceSocketOpened(remoteDevId, socketId); } + +void DmTransPortSecondFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + + std::shared_ptr dmCommToolPtr = std::make_shared(); + std::shared_ptr dmTransPortPtr = std::make_shared(dmCommToolPtr); + dmTransPortPtr->Init(); } -} +} // namespace DistributedHardware +} // namespace OHOS /* Fuzzer entry point */ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) @@ -129,5 +135,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ OHOS::DistributedHardware::DmTransPortFuzzTest(data, size); OHOS::DistributedHardware::DmTransPortFirstFuzzTest(data, size); + OHOS::DistributedHardware::DmTransPortSecondFuzzTest(data, size); return 0; } diff --git a/test/softbusfuzztest/softbusconnector_fuzzer/softbus_connector_fuzzer.cpp b/test/softbusfuzztest/softbusconnector_fuzzer/softbus_connector_fuzzer.cpp index 96704ebe8..384c7e601 100644 --- a/test/softbusfuzztest/softbusconnector_fuzzer/softbus_connector_fuzzer.cpp +++ b/test/softbusfuzztest/softbusconnector_fuzzer/softbus_connector_fuzzer.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022-2024 Huawei Device Co., Ltd. + * Copyright (c) 2022-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 @@ -13,13 +13,16 @@ * limitations under the License. */ -#include "softbus_connector.h" -#include "softbus_bus_center.h" +#include "softbus_connector_fuzzer.h" + +#include + #include "dm_device_info.h" #include "dm_publish_info.h" #include "dm_subscribe_info.h" +#include "softbus_bus_center.h" +#include "softbus_connector.h" #include "softbus_session.h" -#include "softbus_connector_fuzzer.h" namespace OHOS { namespace DistributedHardware { @@ -36,6 +39,93 @@ void SoftBusConnectorFuzzTest(const uint8_t* data, size_t size) std::shared_ptr softbusConnector = std::make_shared(); softbusConnector->OnSoftbusJoinLNNResult(addr, networkId, result); } + +void SoftBusConnectorFirstFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t userId = fdp.ConsumeIntegral(); + std::string credId = fdp.ConsumeRandomLengthString(); + int32_t sessionKeyId = fdp.ConsumeIntegral(); + int32_t aclId = fdp.ConsumeIntegral(); + std::string localUdid = "localDeviceId"; + std::string remoteUdid = "remoteDeviceId"; + DistributedDeviceProfile::AccessControlProfile localAcl; + std::vector acLStrList; + std::string jsonString = fdp.ConsumeRandomLengthString(); + std::vector remoteAllAclList; + std::shared_ptr softbusConnector = std::make_shared(); + softbusConnector->SyncAclList(userId, credId, sessionKeyId, aclId); + DistributedDeviceProfile::Accesser acer; + DistributedDeviceProfile::Accessee acee; + acee.SetAccesseeDeviceId("localDeviceId"); + acer.SetAccesserDeviceId("remoteDeviceId"); + localAcl.SetTrustDeviceId("remoteDeviceId"); + localAcl.SetAccesser(acer); + localAcl.SetAccessee(acee); + softbusConnector->SyncLocalAclList5_1_0(localUdid, remoteUdid, localAcl, acLStrList); + acer.SetAccesserDeviceId("localDeviceId"); + acee.SetAccesseeDeviceId("remoteDeviceId"); + localAcl.SetTrustDeviceId("remoteDeviceId"); + localAcl.SetAccesser(acer); + localAcl.SetAccessee(acee); + softbusConnector->SyncLocalAclList5_1_0(localUdid, remoteUdid, localAcl, acLStrList); + softbusConnector->ParaseAclChecksumList(jsonString, remoteAllAclList); + std::string localVersion = fdp.ConsumeRandomLengthString(); + softbusConnector->GetLocalVersion(localUdid, remoteUdid, localVersion, localAcl); + std::vector aclVerDesc; + std::map remoteAllAclMap; + softbusConnector->SortAclListDesc(remoteAllAclList, aclVerDesc, remoteAllAclMap); + std::vector remoteVerDesc; + softbusConnector->MatchTargetVersion(localVersion, remoteVerDesc); + remoteVerDesc.push_back(fdp.ConsumeRandomLengthString()); + softbusConnector->MatchTargetVersion(localVersion, remoteVerDesc); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string remoteUdidHash = fdp.ConsumeRandomLengthString(); + softbusConnector->JoinLnn(deviceId, remoteUdidHash); +} + +void SoftBusConnectorSecondFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::shared_ptr softbusConnector = std::make_shared(); + int32_t sessionId = fdp.ConsumeIntegral(); + int32_t sessionKeyId = fdp.ConsumeIntegral(); + std::string udid = fdp.ConsumeRandomLengthString(); + std::string udidHash = fdp.ConsumeRandomLengthString(); + int32_t remoteSessionKeyId = fdp.ConsumeIntegral(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + softbusConnector->JoinLNNBySkId(sessionId, sessionKeyId, remoteSessionKeyId, udid, udidHash); + softbusConnector->JoinLnnByHml(sessionId, sessionKeyId, remoteSessionKeyId); + DeviceInfo deviceInfo; + DmDeviceInfo dmDeviceInfo; + memcpy_s(deviceInfo.devId, sizeof(deviceInfo.devId), "deviceId", sizeof("deviceId")); + memcpy_s(deviceInfo.devName, sizeof(deviceInfo.devName), "deviceName", sizeof("deviceName")); + softbusConnector->ConvertDeviceInfoToDmDevice(deviceInfo, dmDeviceInfo); + DmDeviceBasicInfo dmDeviceBasicInfo; + softbusConnector->ConvertDeviceInfoToDmDevice(deviceInfo, dmDeviceBasicInfo); + softbusConnector->GetLocalDeviceNetworkId(); + ProcessInfo processInfo; + softbusConnector->SetProcessInfo(processInfo); + std::vector processInfoVec; + softbusConnector->SetProcessInfoVec(processInfoVec); + softbusConnector->GetProcessInfo(); + softbusConnector->ClearProcessInfo(); + softbusConnector->SetChangeProcessInfo(processInfo); + softbusConnector->GetChangeProcessInfo(); + softbusConnector->ClearChangeProcessInfo(); + softbusConnector->DeleteOffLineTimer(udidHash); + softbusConnector->CheckIsNeedJoinLnn(udid, deviceId); + NodeBasicInfo nodeBasicInfo; + memcpy_s(nodeBasicInfo.networkId, sizeof(nodeBasicInfo.networkId), "networkId", sizeof("networkId")); + memcpy_s(nodeBasicInfo.deviceName, sizeof(nodeBasicInfo.deviceName), "deviceName", sizeof("deviceName")); + softbusConnector->ConvertNodeBasicInfoToDmDevice(nodeBasicInfo, dmDeviceInfo); +} } } @@ -44,6 +134,7 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::SoftBusConnectorFuzzTest(data, size); - + OHOS::DistributedHardware::SoftBusConnectorFirstFuzzTest(data, size); + OHOS::DistributedHardware::SoftBusConnectorSecondFuzzTest(data, size); return 0; } diff --git a/test/softbusfuzztest/softbuslistener_fuzzer/project.xml b/test/softbusfuzztest/softbuslistener_fuzzer/project.xml index 500f6f414..ed4f3e9e5 100644 --- a/test/softbusfuzztest/softbuslistener_fuzzer/project.xml +++ b/test/softbusfuzztest/softbuslistener_fuzzer/project.xml @@ -18,7 +18,7 @@ 1000 - 300 + 10 4096 diff --git a/test/softbusfuzztest/softbuslistener_fuzzer/softbus_listener_fuzzer.cpp b/test/softbusfuzztest/softbuslistener_fuzzer/softbus_listener_fuzzer.cpp index 7041f169d..1647e8ed3 100644 --- a/test/softbusfuzztest/softbuslistener_fuzzer/softbus_listener_fuzzer.cpp +++ b/test/softbusfuzztest/softbuslistener_fuzzer/softbus_listener_fuzzer.cpp @@ -283,6 +283,117 @@ void SoftBusListenerForthFuzzTest(const uint8_t* data, size_t size) std::vector deviceList; softbusListener_->GetAllTrustedDeviceList(pkgName, extra, deviceList); } + +void SoftBusListenerFifthFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + DmDeviceInfo deviceInfo; + softbusListener_->InitSoftbusListener(); + softbusListener_->DeviceOnLine(deviceInfo); + softbusListener_->DeviceOffLine(deviceInfo); + softbusListener_->DeviceNameChange(deviceInfo); + std::string msg = fdp.ConsumeRandomLengthString(); + softbusListener_->DeviceNotTrust(msg); + softbusListener_->DeviceScreenStatusChange(deviceInfo); + std::string deviceList = fdp.ConsumeRandomLengthString(); + int32_t errcode = fdp.ConsumeIntegral(); + uint16_t deviceTypeId = fdp.ConsumeIntegral(); + softbusListener_->CredentialAuthStatusProcess(deviceList, deviceTypeId, errcode); + DevUserInfo localDevUserInfo; + DevUserInfo remoteDevUserInfo; + std::string remoteAclList = fdp.ConsumeRandomLengthString(); + softbusListener_->OnSyncLocalAclList(localDevUserInfo, remoteDevUserInfo, remoteAclList); + std::string aclList = fdp.ConsumeRandomLengthString(); + softbusListener_->OnGetAclListHash(localDevUserInfo, remoteDevUserInfo, aclList); + uint32_t deviceListLen = static_cast(deviceList.length()); + softbusListener_->OnCredentialAuthStatus(deviceList.data(), deviceListLen, deviceTypeId, errcode); + std::shared_ptr info = nullptr; + softbusListener_->UpdateDeviceName(info.get()); + info = std::make_shared(); + softbusListener_->UpdateDeviceName(info.get()); + int32_t publishId = fdp.ConsumeIntegral(); + softbusListener_->StopPublishSoftbusLNN(publishId); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback; + softbusListener_->RegisterSoftbusLnnOpsCbk(pkgName, callback); + callback = std::make_shared(); + softbusListener_->RegisterSoftbusLnnOpsCbk(pkgName, callback); + softbusListener_->UnRegisterSoftbusLnnOpsCbk(pkgName); + std::string networkId = fdp.ConsumeRandomLengthString(); + softbusListener_->GetDeviceInfo(networkId, deviceInfo); + std::string udid = fdp.ConsumeRandomLengthString(); + softbusListener_->GetNetworkIdByUdid(udid, networkId); + std::string deviceName = fdp.ConsumeRandomLengthString(); + softbusListener_->GetDeviceNameByUdid(udid, deviceName); + bool isWakeUp = fdp.ConsumeBool(); + std::string callerId = fdp.ConsumeRandomLengthString(); + softbusListener_->ShiftLNNGear(isWakeUp, callerId); +} + +void SoftBusListenerSixthFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + DmDeviceInfo deviceInfo; + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string networkId = fdp.ConsumeRandomLengthString(); + std::string msg = fdp.ConsumeRandomLengthString(); + uint8_t arr[DATA_LEN] = { 1 }; + size_t len = static_cast(DATA_LEN); + softbusListener_->ConvertBytesToUpperCaseHexString(arr, len); + int32_t networkType = fdp.ConsumeIntegral(); + softbusListener_->GetNetworkTypeByNetworkId(networkId.data(), networkType); + int32_t securityLevel = fdp.ConsumeIntegral(); + softbusListener_->GetDeviceSecurityLevel(networkId.data(), securityLevel); + std::string name = fdp.ConsumeRandomLengthString(); + softbusListener_->CloseDmRadarHelperObj(name); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string ip = fdp.ConsumeRandomLengthString(); + ConnectionAddrType addrType = ConnectionAddrType::CONNECTION_ADDR_ETH; + softbusListener_->GetIPAddrTypeFromCache(deviceId, ip, addrType); + softbusListener_->SendAclChangedBroadcast(msg); + softbusListener_->GetSoftbusRefreshCb(); + int32_t screenStatus = fdp.ConsumeIntegral(); + softbusListener_->GetDeviceScreenStatus(networkId.data(), screenStatus); + std::string remoteUserId = fdp.ConsumeRandomLengthString(); + std::vector userIds; + softbusListener_->SetForegroundUserIdsToDSoftBus(remoteUserId, userIds); + softbusListener_->DeleteCacheDeviceInfo(); + std::string displayName = fdp.ConsumeRandomLengthString(); + softbusListener_->SetLocalDisplayName(displayName); + DistributedDeviceProfile::AccessControlProfile profile; + softbusListener_->ConvertAclToDeviceInfo(profile, deviceInfo); + std::string extra = fdp.ConsumeRandomLengthString(); + std::vector devList; + softbusListener_->GetAllTrustedDeviceList(pkgName, extra, devList); + std::shared_ptr customDataJson = std::make_shared(); + int32_t actionId = fdp.ConsumeIntegral(); + softbusListener_->GetAttrFromCustomData(customDataJson.get(), deviceInfo, actionId); +} + +void SoftBusListenerSeventhFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + NodeBasicInfo nodeBasicInfo = { .networkId = { "networkId" }, + .deviceName = { "deviceNameInfo" }, + .deviceTypeId = 1, + .osType = 1, + .osVersion = "onVersion" }; + int32_t devScreenStatus = fdp.ConsumeIntegral(); + DmDeviceInfo devInfo; + softbusListener_->ConvertScreenStatusToDmDevice(nodeBasicInfo, devScreenStatus, devInfo); + softbusListener_->ConvertNodeBasicInfoToDmDevice(nodeBasicInfo, devInfo); + DmDeviceBasicInfo dmdevInfo; + softbusListener_->ConvertNodeBasicInfoToDmDevice(nodeBasicInfo, dmdevInfo); +} } } @@ -295,6 +406,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) OHOS::DistributedHardware::SoftBusListenerSecondFuzzTest(data, size); OHOS::DistributedHardware::SoftBusListenerThirdFuzzTest(data, size); OHOS::DistributedHardware::SoftBusListenerForthFuzzTest(data, size); - + OHOS::DistributedHardware::SoftBusListenerFifthFuzzTest(data, size); + OHOS::DistributedHardware::SoftBusListenerSixthFuzzTest(data, size); + OHOS::DistributedHardware::SoftBusListenerSeventhFuzzTest(data, size); return 0; } -- Gitee From 031efc4ee1b6c23450e9287e5f09dce7180384da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Sun, 22 Jun 2025 18:54:02 +0800 Subject: [PATCH 2/7] add FUZZ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../json_object_nlohmannjson_fuzzer.cpp | 40 +++++++++---------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.cpp b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.cpp index dbb463c0a..01b307c11 100644 --- a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.cpp +++ b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.cpp @@ -34,28 +34,28 @@ void JsonObjectNlohmannjsonFuzzTest(const uint8_t* data, size_t size) JsonItemObject itemObject; JsonItemObject itemObjectNew; itemObject["key1"] = fdp.ConsumeIntegral(); - std::string str_value = fdp.ConsumeRandomLengthString(); - int16_t int16_value = fdp.ConsumeIntegral(); - double double_value = fdp.ConsumeFloatingPoint(); - bool bool_value = fdp.ConsumeBool(); - uint8_t uint8_value = fdp.ConsumeIntegral(); - uint16_t uint16_value = fdp.ConsumeIntegral(); - uint32_t uint32_value = fdp.ConsumeIntegral(); - int64_t int64_value = fdp.ConsumeIntegral(); - ToJson(itemObject, double_value); - ToJson(itemObject, int16_value); - FromJson(itemObject, double_value); - FromJson(itemObject, bool_value); - FromJson(itemObject, uint8_value); - FromJson(itemObject, uint16_value); + std::string strValue = fdp.ConsumeRandomLengthString(); + int16_t int16Value = fdp.ConsumeIntegral(); + double doubleValue = fdp.ConsumeFloatingPoint(); + bool boolValue = fdp.ConsumeBool(); + uint8_t uint8Value = fdp.ConsumeIntegral(); + uint16_t uint16Value = fdp.ConsumeIntegral(); + uint32_t uint32Value = fdp.ConsumeIntegral(); + int64_t int64Value = fdp.ConsumeIntegral(); + ToJson(itemObject, doubleValue); + ToJson(itemObject, int16Value); + FromJson(itemObject, doubleValue); + FromJson(itemObject, boolValue); + FromJson(itemObject, uint8Value); + FromJson(itemObject, uint16Value); itemObject.IsNumber(); itemObjectNew = itemObject; - itemObjectNew.PushBack(str_value); - itemObjectNew.PushBack(double_value); - itemObjectNew.PushBack(int64_value); - itemObjectNew.GetTo(double_value); - itemObjectNew.GetTo(uint32_value); - itemObjectNew.GetTo(bool_value); + itemObjectNew.PushBack(strValue); + itemObjectNew.PushBack(doubleValue); + itemObjectNew.PushBack(int64Value); + itemObjectNew.GetTo(doubleValue); + itemObjectNew.GetTo(uint32Value); + itemObjectNew.GetTo(boolValue); } } } -- Gitee From 0bae8f36f8c40fd94215c4ee3a604d40d6b2b9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Sun, 22 Jun 2025 19:02:20 +0800 Subject: [PATCH 3/7] add FUZZ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../softbuslistener_fuzzer/softbus_listener_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/softbusfuzztest/softbuslistener_fuzzer/softbus_listener_fuzzer.cpp b/test/softbusfuzztest/softbuslistener_fuzzer/softbus_listener_fuzzer.cpp index 1647e8ed3..bdce67ed3 100644 --- a/test/softbusfuzztest/softbuslistener_fuzzer/softbus_listener_fuzzer.cpp +++ b/test/softbusfuzztest/softbuslistener_fuzzer/softbus_listener_fuzzer.cpp @@ -302,7 +302,7 @@ void SoftBusListenerFifthFuzzTest(const uint8_t* data, size_t size) int32_t errcode = fdp.ConsumeIntegral(); uint16_t deviceTypeId = fdp.ConsumeIntegral(); softbusListener_->CredentialAuthStatusProcess(deviceList, deviceTypeId, errcode); - DevUserInfo localDevUserInfo; + DevUserInfo localDevUserInfo; DevUserInfo remoteDevUserInfo; std::string remoteAclList = fdp.ConsumeRandomLengthString(); softbusListener_->OnSyncLocalAclList(localDevUserInfo, remoteDevUserInfo, remoteAclList); -- Gitee From 6fb9fd06f6ea4926cb81ffcbbcda3560980ce9aa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Mon, 23 Jun 2025 09:20:11 +0800 Subject: [PATCH 4/7] add FUZZ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- test/jsonfuzztest/BUILD.gn | 20 ------ .../jsonobjectnlohmannjson_fuzzer/BUILD.gn | 63 ----------------- .../jsonobjectnlohmannjson_fuzzer/corpus/init | 13 ---- .../json_object_nlohmannjson_fuzzer.cpp | 70 ------------------- .../json_object_nlohmannjson_fuzzer.h | 21 ------ .../jsonobjectnlohmannjson_fuzzer/project.xml | 25 ------- 6 files changed, 212 deletions(-) delete mode 100644 test/jsonfuzztest/BUILD.gn delete mode 100644 test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/BUILD.gn delete mode 100644 test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/corpus/init delete mode 100644 test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.cpp delete mode 100644 test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.h delete mode 100644 test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/project.xml diff --git a/test/jsonfuzztest/BUILD.gn b/test/jsonfuzztest/BUILD.gn deleted file mode 100644 index bb5efd0aa..000000000 --- a/test/jsonfuzztest/BUILD.gn +++ /dev/null @@ -1,20 +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. - -group("fuzztest") { - testonly = true - - deps = [ - "jsonobjectnlohmannjson_fuzzer:fuzztest", - ] -} diff --git a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/BUILD.gn b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/BUILD.gn deleted file mode 100644 index e90d83b3b..000000000 --- a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/BUILD.gn +++ /dev/null @@ -1,63 +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/distributedhardware/device_manager/device_manager.gni") - -##############################fuzztest########################################## -ohos_fuzztest("JsonObjectNlohmannjsonFuzzTest") { - module_out_path = fuzz_test_output_path - fuzz_config_file = "${devicemanager_path}/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer" - - include_dirs = [ - "${common_path}/include", - "${json_path}/include", - ] - - cflags = [ - "-g", - "-O0", - "-Dprivate=public", - "-Dprotected=public", - "-Werror", - "-Wno-unused-variable", - "-fno-omit-frame-pointer", - ] - - sources = [ "json_object_nlohmannjson_fuzzer.cpp", - "${json_path}/src/json_object_cjson.cpp", ] - - deps = [] - - external_deps = [ - "cJSON:cjson", - "c_utils:utils", - "hilog:libhilog", - ] - - defines = [ - "HI_LOG_ENABLE", - "DH_LOG_TAG=\"JsonObjectNlohmannjsonFuzzTest\"", - "LOG_DOMAIN=0xD004110", - ] -} - -############################################################################### -group("fuzztest") { - testonly = true - - deps = [ ":JsonObjectNlohmannjsonFuzzTest" ] -} -############################################################################### diff --git a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/corpus/init b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/corpus/init deleted file mode 100644 index 8f37f0925..000000000 --- a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/corpus/init +++ /dev/null @@ -1,13 +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/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.cpp b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.cpp deleted file mode 100644 index 01b307c11..000000000 --- a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.cpp +++ /dev/null @@ -1,70 +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 "json_object_nlohmannjson_fuzzer.h" - -#include -#include -#include -#include - -#include "dm_constants.h" -#include "json_object.h" -namespace OHOS { -namespace DistributedHardware { - -void JsonObjectNlohmannjsonFuzzTest(const uint8_t* data, size_t size) -{ - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - JsonItemObject itemObject; - JsonItemObject itemObjectNew; - itemObject["key1"] = fdp.ConsumeIntegral(); - std::string strValue = fdp.ConsumeRandomLengthString(); - int16_t int16Value = fdp.ConsumeIntegral(); - double doubleValue = fdp.ConsumeFloatingPoint(); - bool boolValue = fdp.ConsumeBool(); - uint8_t uint8Value = fdp.ConsumeIntegral(); - uint16_t uint16Value = fdp.ConsumeIntegral(); - uint32_t uint32Value = fdp.ConsumeIntegral(); - int64_t int64Value = fdp.ConsumeIntegral(); - ToJson(itemObject, doubleValue); - ToJson(itemObject, int16Value); - FromJson(itemObject, doubleValue); - FromJson(itemObject, boolValue); - FromJson(itemObject, uint8Value); - FromJson(itemObject, uint16Value); - itemObject.IsNumber(); - itemObjectNew = itemObject; - itemObjectNew.PushBack(strValue); - itemObjectNew.PushBack(doubleValue); - itemObjectNew.PushBack(int64Value); - itemObjectNew.GetTo(doubleValue); - itemObjectNew.GetTo(uint32Value); - itemObjectNew.GetTo(boolValue); -} -} -} - -/* Fuzzer entry point */ -extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) -{ - /* Run your code on data */ - OHOS::DistributedHardware::JsonObjectNlohmannjsonFuzzTest(data, size); - - return 0; -} diff --git a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.h b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_fuzzer.h deleted file mode 100644 index f01aa3031..000000000 --- a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/json_object_nlohmannjson_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 JSON_OBJECT_NLOHMANNJSON_FUZZER_H -#define JSON_OBJECT_NLOHMANNJSON_FUZZER_H - -#define FUZZ_PROJECT_NAME "jsonobjectnlohmannjson_fuzzer" - -#endif // JSON_OBJECT_NLOHMANNJSON_FUZZER_H \ No newline at end of file diff --git a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/project.xml b/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/project.xml deleted file mode 100644 index 500f6f414..000000000 --- a/test/jsonfuzztest/jsonobjectnlohmannjson_fuzzer/project.xml +++ /dev/null @@ -1,25 +0,0 @@ - - - - - - 1000 - - 300 - - 4096 - - \ No newline at end of file -- Gitee From 7fd0c6803027a62a3c37cfc4af7c64cb1d360be3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Mon, 23 Jun 2025 09:38:45 +0800 Subject: [PATCH 5/7] add FUZZ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- test/BUILD.gn | 1 - 1 file changed, 1 deletion(-) diff --git a/test/BUILD.gn b/test/BUILD.gn index f756c7a5e..c856a29d0 100644 --- a/test/BUILD.gn +++ b/test/BUILD.gn @@ -20,7 +20,6 @@ group("test") { "benchmarktest:benchmarktest", "commonfuzztest:fuzztest", "interfacesfuzztest:fuzztest", - "jsonfuzztest:fuzztest", "servicesfuzztest:fuzztest", "softbusfuzztest:fuzztest", "unittest:unittest", -- Gitee From 70f02b73bb076a87f3bd1a9720885d553a5b7056 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A6=E5=9B=BD=E5=BA=86?= Date: Mon, 23 Jun 2025 15:10:18 +0800 Subject: [PATCH 6/7] add FUZZ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韦国庆 --- test/softbusfuzztest/softbuslistener_fuzzer/project.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/softbusfuzztest/softbuslistener_fuzzer/project.xml b/test/softbusfuzztest/softbuslistener_fuzzer/project.xml index ed4f3e9e5..500f6f414 100644 --- a/test/softbusfuzztest/softbuslistener_fuzzer/project.xml +++ b/test/softbusfuzztest/softbuslistener_fuzzer/project.xml @@ -18,7 +18,7 @@ 1000 - 10 + 300 4096 -- Gitee From badc6abf7a37ee6bf9808b2bae711dba8c75d0b3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=9F=A6=E5=9B=BD=E5=BA=86?= Date: Mon, 23 Jun 2025 15:38:54 +0800 Subject: [PATCH 7/7] add FUZZ MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 韦国庆 --- test/commonfuzztest/BUILD.gn | 6 +- test/commonfuzztest/authacl_fuzzer/BUILD.gn | 80 +++ .../authacl_fuzzer/auth_acl_fuzzer.cpp | 50 ++ .../authacl_fuzzer/auth_acl_fuzzer.h | 21 + .../commonfuzztest/authacl_fuzzer/corpus/init | 13 + .../commonfuzztest/authacl_fuzzer/project.xml | 25 + .../authcredential_fuzzer/BUILD.gn | 80 +++ .../auth_credential_fuzzer.cpp | 71 +++ .../auth_credential_fuzzer.h | 21 + .../authcredential_fuzzer/corpus/init | 13 + .../authcredential_fuzzer/project.xml | 25 + .../commonfuzztest/dmanonyous_fuzzer/BUILD.gn | 75 +++ .../dmanonyous_fuzzer/corpus/init | 13 + .../dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp | 76 +++ .../dmanonyous_fuzzer/dm_anonyous_fuzzer.h | 21 + .../dmanonyous_fuzzer/project.xml | 25 + .../dmfreezeprocess_fuzzer/BUILD.gn | 80 +++ .../dmfreezeprocess_fuzzer/corpus/init | 13 + .../dm_freeze_process_fuzzer.cpp | 87 +++ .../dm_freeze_process_fuzzer.h | 21 + .../dmfreezeprocess_fuzzer/project.xml | 25 + .../devicemanagerimpl_fuzzer/BUILD.gn | 2 +- .../device_manager_impl_fuzzer.cpp | 525 +++++++++--------- test/servicesfuzztest/BUILD.gn | 1 + .../dmauthattestcommon_fuzzer/BUILD.gn | 80 +++ .../dmauthattestcommon_fuzzer/corpus/init | 13 + .../dm_auth_attest_common_fuzzer.cpp | 56 ++ .../dm_auth_attest_common_fuzzer.h | 21 + .../dmauthattestcommon_fuzzer/project.xml | 25 + .../dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp | 27 + .../dm_transport_msg_fuzzer.cpp | 30 + 31 files changed, 1371 insertions(+), 250 deletions(-) create mode 100644 test/commonfuzztest/authacl_fuzzer/BUILD.gn create mode 100644 test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp create mode 100644 test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.h create mode 100644 test/commonfuzztest/authacl_fuzzer/corpus/init create mode 100644 test/commonfuzztest/authacl_fuzzer/project.xml create mode 100644 test/commonfuzztest/authcredential_fuzzer/BUILD.gn create mode 100644 test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.cpp create mode 100644 test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.h create mode 100644 test/commonfuzztest/authcredential_fuzzer/corpus/init create mode 100644 test/commonfuzztest/authcredential_fuzzer/project.xml create mode 100644 test/commonfuzztest/dmanonyous_fuzzer/BUILD.gn create mode 100644 test/commonfuzztest/dmanonyous_fuzzer/corpus/init create mode 100644 test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp create mode 100644 test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.h create mode 100644 test/commonfuzztest/dmanonyous_fuzzer/project.xml create mode 100644 test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn create mode 100644 test/commonfuzztest/dmfreezeprocess_fuzzer/corpus/init create mode 100644 test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.cpp create mode 100644 test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.h create mode 100644 test/commonfuzztest/dmfreezeprocess_fuzzer/project.xml create mode 100644 test/servicesfuzztest/dmauthattestcommon_fuzzer/BUILD.gn create mode 100644 test/servicesfuzztest/dmauthattestcommon_fuzzer/corpus/init create mode 100644 test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.cpp create mode 100644 test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.h create mode 100644 test/servicesfuzztest/dmauthattestcommon_fuzzer/project.xml diff --git a/test/commonfuzztest/BUILD.gn b/test/commonfuzztest/BUILD.gn index 617816463..b5f1f8d01 100644 --- a/test/commonfuzztest/BUILD.gn +++ b/test/commonfuzztest/BUILD.gn @@ -1,4 +1,4 @@ -# Copyright (c) 2022-2024 Huawei Device Co., Ltd. +# Copyright (c) 2022-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 @@ -15,13 +15,17 @@ group("fuzztest") { testonly = true deps = [ + "authacl_fuzzer:fuzztest", + "authcredential_fuzzer:fuzztest", "authenticatedevice_fuzzer:fuzztest", "authenticatedeviceservice_fuzzer:fuzztest", "authenticatedeviceserviceimpl_fuzzer:fuzztest", "dmauthmanager_fuzzer:fuzztest", "dmauthmanagerv2_fuzzer:fuzztest", + "dmanonyous_fuzzer:fuzztest", "dmcommoneventmanager_fuzzer:fuzztest", "dmcredentialimpl_fuzzer:fuzztest", + "dmfreezeprocess_fuzzer:fuzztest", "dmnegotiateprocess_fuzzer:fuzztest", "generateencrypteduuid_fuzzer:fuzztest", "getdeviceinfo_fuzzer:fuzztest", diff --git a/test/commonfuzztest/authacl_fuzzer/BUILD.gn b/test/commonfuzztest/authacl_fuzzer/BUILD.gn new file mode 100644 index 000000000..6800b459d --- /dev/null +++ b/test/commonfuzztest/authacl_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("AuthAclFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/commonfuzztest/authacl_fuzzer" + + include_dirs = [ + "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/authentication_v2", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/dependency/timer", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "auth_acl_fuzzer.cpp" ] + + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${services_path}:devicemanagerservicetest", + "${servicesimpl_path}:devicemanagerserviceimpl", + "${utils_path}:devicemanagerutilstest", + ] + + external_deps = [ + "cJSON:cjson", + "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", + "init:libbegetutil", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"AuthAclFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":AuthAclFuzzTest" ] +} +############################################################################### diff --git a/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp new file mode 100644 index 000000000..327347467 --- /dev/null +++ b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.cpp @@ -0,0 +1,50 @@ +/* + * Copyright (c) 2025-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 "auth_acl_fuzzer.h" + +#include +#include + +#include "device_manager_service_listener.h" +#include "dm_auth_state.h" +#include "dm_freeze_process.h" + +namespace OHOS { +namespace DistributedHardware { +void AuthAclFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t sessionId = fdp.ConsumeIntegral(); + std::string result = fdp.ConsumeRandomLengthString(); + std::shared_ptr authSink = std::make_shared(); + std::shared_ptr authSrc = std::make_shared(); + + authSink->GetStateType(); + authSrc->GetStateType(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::AuthAclFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.h b/test/commonfuzztest/authacl_fuzzer/auth_acl_fuzzer.h new file mode 100644 index 000000000..6e30090a7 --- /dev/null +++ b/test/commonfuzztest/authacl_fuzzer/auth_acl_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 AUTH_ACL_FUZZER_H +#define AUTH_ACL_FUZZER_H + +#define FUZZ_PROJECT_NAME "authacl_fuzzer" + +#endif // AUTH_ACL_FUZZER_H \ No newline at end of file diff --git a/test/commonfuzztest/authacl_fuzzer/corpus/init b/test/commonfuzztest/authacl_fuzzer/corpus/init new file mode 100644 index 000000000..8f37f0925 --- /dev/null +++ b/test/commonfuzztest/authacl_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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/test/commonfuzztest/authacl_fuzzer/project.xml b/test/commonfuzztest/authacl_fuzzer/project.xml new file mode 100644 index 000000000..500f6f414 --- /dev/null +++ b/test/commonfuzztest/authacl_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/commonfuzztest/authcredential_fuzzer/BUILD.gn b/test/commonfuzztest/authcredential_fuzzer/BUILD.gn new file mode 100644 index 000000000..5928e20dd --- /dev/null +++ b/test/commonfuzztest/authcredential_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("AuthCredentialFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/commonfuzztest/authcredential_fuzzer" + + include_dirs = [ + "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/authentication_v2", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/dependency/timer", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "auth_credential_fuzzer.cpp" ] + + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${services_path}:devicemanagerservicetest", + "${servicesimpl_path}:devicemanagerserviceimpl", + "${utils_path}:devicemanagerutilstest", + ] + + external_deps = [ + "cJSON:cjson", + "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", + "init:libbegetutil", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"AuthCredentialFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":AuthCredentialFuzzTest" ] +} +############################################################################### diff --git a/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.cpp b/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.cpp new file mode 100644 index 000000000..4f5e040fc --- /dev/null +++ b/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.cpp @@ -0,0 +1,71 @@ +/* + * 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 "auth_credential_fuzzer.h" + +#include +#include + +#include "device_manager_service_listener.h" +#include "dm_auth_state.h" +#include "dm_freeze_process.h" + +namespace OHOS { +namespace DistributedHardware { +constexpr uint32_t SERVICE = 2; + +void AuthCredentialFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FreezeProcess freezeProcess; + FuzzedDataProvider fdp(data, size); + std::shared_ptr context = std::make_shared(); + context->transmitData = fdp.ConsumeRandomLengthString(); + context->requestId = fdp.ConsumeIntegral(); + context->accesser.userId = fdp.ConsumeIntegral(); + context->accesser.isGenerateLnnCredential = true; + context->isAppCredentialVerified = false; + context->accesser.bindLevel = SERVICE; + std::shared_ptr authFirst = std::make_shared(); + std::shared_ptr authSecond = std::make_shared(); + std::shared_ptr authThird = std::make_shared(); + std::shared_ptr authForth = std::make_shared(); + std::shared_ptr authFifth = std::make_shared(); + std::shared_ptr authSixth = std::make_shared(); + + authFirst->Action(context); + authSecond->Action(context); + context->isAppCredentialVerified = true; + authSecond->Action(context); + context->accesser.isGenerateLnnCredential = false; + authFirst->GetStateType(); + authSecond->GetStateType(); + authThird->GetStateType(); + authForth->GetStateType(); + authFifth->GetStateType(); + authSixth->GetStateType(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::AuthCredentialFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.h b/test/commonfuzztest/authcredential_fuzzer/auth_credential_fuzzer.h new file mode 100644 index 000000000..6e30090a7 --- /dev/null +++ b/test/commonfuzztest/authcredential_fuzzer/auth_credential_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 AUTH_ACL_FUZZER_H +#define AUTH_ACL_FUZZER_H + +#define FUZZ_PROJECT_NAME "authacl_fuzzer" + +#endif // AUTH_ACL_FUZZER_H \ No newline at end of file diff --git a/test/commonfuzztest/authcredential_fuzzer/corpus/init b/test/commonfuzztest/authcredential_fuzzer/corpus/init new file mode 100644 index 000000000..8f37f0925 --- /dev/null +++ b/test/commonfuzztest/authcredential_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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/test/commonfuzztest/authcredential_fuzzer/project.xml b/test/commonfuzztest/authcredential_fuzzer/project.xml new file mode 100644 index 000000000..500f6f414 --- /dev/null +++ b/test/commonfuzztest/authcredential_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/commonfuzztest/dmanonyous_fuzzer/BUILD.gn b/test/commonfuzztest/dmanonyous_fuzzer/BUILD.gn new file mode 100644 index 000000000..dfc1d5b80 --- /dev/null +++ b/test/commonfuzztest/dmanonyous_fuzzer/BUILD.gn @@ -0,0 +1,75 @@ +# 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("DmAnonyousFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = "${devicemanager_path}/test/commonfuzztest/dmanonyous_fuzzer" + + include_dirs = [ + "${common_path}/include", + "${innerkits_path}/native_cpp/include", + "${services_path}/include/softbus", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dm_anonyous_fuzzer.cpp", + "${json_path}/src/json_object_cjson.cpp", ] + + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${services_path}:devicemanagerservicetest", + "${servicesimpl_path}:devicemanagerserviceimpl", + ] + + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "device_auth:deviceauth_sdk", + "device_info_manager:distributed_device_profile_common", + "device_info_manager:distributed_device_profile_sdk", + "dsoftbus:softbus_client", + "hilog:libhilog", + "ipc:ipc_single", + "safwk:system_ability_fwk", + "samgr:samgr_proxy", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DmAnonyousFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DmAnonyousFuzzTest" ] +} +############################################################################### diff --git a/test/commonfuzztest/dmanonyous_fuzzer/corpus/init b/test/commonfuzztest/dmanonyous_fuzzer/corpus/init new file mode 100644 index 000000000..8f37f0925 --- /dev/null +++ b/test/commonfuzztest/dmanonyous_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp new file mode 100644 index 000000000..dafa558a4 --- /dev/null +++ b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.cpp @@ -0,0 +1,76 @@ +/* + * 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_manager_impl.h" +#include "dm_constants.h" +#include "softbus_listener.h" +#include "dm_anonymous.h" +namespace OHOS { +namespace DistributedHardware { + +void DmAnonyousFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + std::vector strList; + int64_t testNumber = 123; + int64_t decimal = 10; + strList.push_back("test1"); + strList.push_back("test2"); + GetAnonyStringList(strList); + std::vector intList; + intList.push_back(1); + GetAnonyInt32List(intList); + JsonObject jsonObj; + jsonObj["key1"] = testNumber; + jsonObj["key2"] = "value2"; + jsonObj["key3"] = true; + IsUint32(jsonObj, "key1"); + IsUint64(jsonObj, "key1"); + IsBool(jsonObj, "key3"); + std::map paramMap; + paramMap["key1"] = "value1"; + paramMap["key2"] = "value2"; + std::map paramMap2 = {}; + std::string jsonStr = ConvertMapToJsonString(paramMap); + ParseMapFromJsonString(jsonStr, paramMap2); + StringToInt("123", decimal); + StringToInt64("123", decimal); + int32_t versionNum = 0; + GetVersionNumber("1.0.0", versionNum); + GetCallerPkgName("com.example.app#test"); + GetSubscribeId("123#12345"); + std::multimap unorderedmap; + unorderedmap.insert(std::make_pair("key1", testNumber)); + IsValueExist(unorderedmap, "key1", testNumber); + GetSubStr("test#123", "#", 0); + IsJsonValIntegerString(jsonObj, "key2"); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DmAnonyousFuzzTest(data, size); + + return 0; +} diff --git a/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.h b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_fuzzer.h new file mode 100644 index 000000000..8047cdb14 --- /dev/null +++ b/test/commonfuzztest/dmanonyous_fuzzer/dm_anonyous_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 DM_ANONYOUS_TEST_FUZZER_H +#define DM_ANONYOUS_TEST_FUZZER_H + +#define FUZZ_PROJECT_NAME "dmanonyous_fuzzer" + +#endif // DM_ANONYOUS_TEST_FUZZER_H diff --git a/test/commonfuzztest/dmanonyous_fuzzer/project.xml b/test/commonfuzztest/dmanonyous_fuzzer/project.xml new file mode 100644 index 000000000..500f6f414 --- /dev/null +++ b/test/commonfuzztest/dmanonyous_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn b/test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn new file mode 100644 index 000000000..01ef24d27 --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# 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("DmFreezeProcessFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/commonfuzztest/dmfreezeprocess_fuzzer" + + include_dirs = [ + "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/authentication_v2", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/dependency/timer", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "dm_freeze_process_fuzzer.cpp" ] + + deps = [ + "${innerkits_path}/native_cpp:devicemanagersdk", + "${services_path}:devicemanagerservicetest", + "${servicesimpl_path}:devicemanagerserviceimpl", + "${utils_path}:devicemanagerutilstest", + ] + + external_deps = [ + "cJSON:cjson", + "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", + "init:libbegetutil", + "ipc:ipc_single", + "safwk:system_ability_fwk", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DmFreezeProcessFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DmFreezeProcessFuzzTest" ] +} +############################################################################### diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/corpus/init b/test/commonfuzztest/dmfreezeprocess_fuzzer/corpus/init new file mode 100644 index 000000000..8f37f0925 --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.cpp b/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.cpp new file mode 100644 index 000000000..b4c2c902e --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.cpp @@ -0,0 +1,87 @@ +/* + * Copyright (c) 2025-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 "dm_freeze_process_fuzzer.h" + +#include +#include + +#include "device_manager_service_listener.h" +#include "dm_freeze_process.h" + +namespace OHOS { +namespace DistributedHardware { +namespace { +constexpr const char* BIND_FAILED_EVENTS_KEY = "bindFailedEvents"; +constexpr const char* FREEZE_STATE_KEY = "freezeState"; +constexpr const char* START_FREEZE_TIME_KEY = "startFreezeTimeStamp"; +constexpr const char* STOP_FREEZE_TIME_KEY = "stopFreezeTimeStamp"; +constexpr const char* FAILED_TIMES_STAMPS_KEY = "failedTimeStamps"; +constexpr const char* FREEZE_TIMES_STAMPS_KEY = "freezeTimeStamps"; +constexpr const char* CAST_BUNDLE_NAME = "cast_engine_service"; +constexpr int32_t MAX_CONTINUEOUS_BIND_FAILED_NUM = 2; +constexpr int64_t CONTINUEOUS_FAILED_INTERVAL = 6 * 60; +constexpr int64_t DATA_REFRESH_INTERVAL = 20 * 60; +constexpr int64_t NOT_FREEZE_TIME = 0; +constexpr int64_t FIRST_FREEZE_TIME = 60; +constexpr int64_t SECOND_FREEZE_TIME = 3 * 60; +constexpr int64_t THIRD_FREEZE_TIME = 5 * 60; +constexpr int64_t MAX_FREEZE_TIME = 10 * 60; +} // namespace + +void DmFreezeProcessFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t sessionId = fdp.ConsumeIntegral(); + std::string result = fdp.ConsumeRandomLengthString(); + DeviceFreezeState freezeStateObj; + BindFailedEvents bindFailedEvents; + std::string bundleName = CAST_BUNDLE_NAME; + int32_t deviceType = DEVICE_TYPE_TV; + int64_t reservedDataTimeStamp = fdp.ConsumeIntegral(); + FreezeProcess::GetInstance().ConvertJsonToDeviceFreezeState(result, freezeStateObj); + FreezeProcess::GetInstance().ConvertJsonToBindFailedEvents(result, bindFailedEvents); + bundleName = fdp.ConsumeRandomLengthString(); + deviceType = fdp.ConsumeIntegral(); + FreezeProcess::GetInstance().CleanBindFailedEvents(reservedDataTimeStamp); + FreezeProcess::GetInstance().CleanFreezeState(reservedDataTimeStamp); + FreezeProcess::GetInstance().ConvertDeviceFreezeStateToJson(freezeStateObj, result); + int64_t nowTime = NOT_FREEZE_TIME; + + int64_t nextTime = fdp.ConsumeIntegral(); + FreezeProcess::GetInstance().CleanFreezeRecord(nowTime); + FreezeProcess::GetInstance().UpdateFreezeState(nowTime); + FreezeProcess::GetInstance().CalculateNextFreezeTime(nowTime, nextTime); + nowTime = FIRST_FREEZE_TIME; + FreezeProcess::GetInstance().CalculateNextFreezeTime(nowTime, nextTime); + nowTime = SECOND_FREEZE_TIME; + FreezeProcess::GetInstance().CalculateNextFreezeTime(nowTime, nextTime); + nowTime = MAX_FREEZE_TIME; + FreezeProcess::GetInstance().CalculateNextFreezeTime(nowTime, nextTime); + FreezeProcess::GetInstance().DeleteFreezeRecord(); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DmFreezeProcessFuzzTest(data, size); + return 0; +} \ No newline at end of file diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.h b/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_fuzzer.h new file mode 100644 index 000000000..0628940ed --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/dm_freeze_process_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 DM_FREE_PROCESS_FUZZER_H +#define DM_FREE_PROCESS_FUZZER_H + +#define FUZZ_PROJECT_NAME "dmfreezeprocess_fuzzer" + +#endif // DM_FREE_PROCESS_FUZZER_H \ No newline at end of file diff --git a/test/commonfuzztest/dmfreezeprocess_fuzzer/project.xml b/test/commonfuzztest/dmfreezeprocess_fuzzer/project.xml new file mode 100644 index 000000000..500f6f414 --- /dev/null +++ b/test/commonfuzztest/dmfreezeprocess_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn index a706fd85f..a7e9c7038 100755 --- a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn +++ b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/BUILD.gn @@ -63,7 +63,7 @@ ohos_fuzztest("DeviceManagerImplFuzzTest") { deps = [ "${innerkits_path}/native_cpp:devicemanagersdk", - "${utils_path}:devicemanagerutils", + "${utils_path}:devicemanagerutilstest", ] defines = [ diff --git a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp index 69cebe8cf..a42e45145 100755 --- a/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp +++ b/test/interfacesfuzztest/devicemanagerimpl_fuzzer/device_manager_impl_fuzzer.cpp @@ -13,253 +13,282 @@ * limitations under the License. */ - #include - #include - #include - #include - #include - #include - #include +#include +#include +#include +#include +#include +#include +#include - #include "device_manager_impl.h" - - namespace OHOS { - namespace DistributedHardware { - - namespace { - - } - - void StopAuthenticateDeviceTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().StopAuthenticateDevice(pkgName); - DeviceManagerImpl::GetInstance().OnDmServiceDied(); - } - - void UnBindDeviceTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string deviceId = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().UnBindDevice(pkgName, deviceId); - } - - void ShiftLNNGearTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().ShiftLNNGear(pkgName); - } - - void RegDevTrustChangeCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::shared_ptr callback = nullptr; - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().RegDevTrustChangeCallback(pkgName, callback); - } - - void GetNetworkIdByUdidTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string udid = fdp.ConsumeRandomLengthString(); - std::string networkId = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().GetNetworkIdByUdid(pkgName, udid, networkId); - } - - void RegisterCredentialAuthStatusCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().RegisterCredentialAuthStatusCallback(pkgName, callback); - } - - void GetAllTrustedDeviceListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string extra = fdp.ConsumeRandomLengthString(); - std::vector deviceList; - DeviceManagerImpl::GetInstance().GetAllTrustedDeviceList(pkgName, extra, deviceList); - } - - void RegisterSinkBindCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().RegisterSinkBindCallback(pkgName, callback); - } - - void GetDeviceProfileInfoListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DmDeviceProfileInfoFilterOptions filterOptions; - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); - } - - void GetDeviceIconInfoTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DmDeviceProfileInfoFilterOptions filterOptions; - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); - } - - void PutDeviceProfileInfoListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::vector deviceProfileInfoList; - DeviceManagerImpl::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); - } - - void GetLocalDisplayDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string displayName = fdp.ConsumeRandomLengthString(); - int32_t maxNameLength = fdp.ConsumeIntegral(); - DeviceManagerImpl::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); - } - - void GetDeviceNetworkIdListTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string bundleName = fdp.ConsumeRandomLengthString(); - NetworkIdQueryFilter queryFilter; - std::vector networkIds; - DeviceManagerImpl::GetInstance().GetDeviceNetworkIdList(bundleName, queryFilter, networkIds); - } - - void SetLocalDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string deviceName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().SetLocalDeviceName(pkgName, deviceName, callback); - } - - void SetRemoteDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - std::string deviceId = fdp.ConsumeRandomLengthString(); - std::string deviceName = fdp.ConsumeRandomLengthString(); - std::shared_ptr callback = nullptr; - DeviceManagerImpl::GetInstance().SetRemoteDeviceName(pkgName, deviceId, deviceName, callback); - } - - void RestoreLocalDeviceNameTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().RestoreLocalDeviceName(pkgName); - } - - void GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size < sizeof(int32_t))) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string bundleName = fdp.ConsumeRandomLengthString(); - int32_t maxNameLength = fdp.ConsumeIntegral(); - DMLocalServiceInfo info; - DeviceManagerImpl::GetInstance(). - GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, maxNameLength, info); - } - - void UnRegisterPinHolderCallbackTest(const uint8_t* data, size_t size) - { - if ((data == nullptr) || (size == 0)) { - return; - } - FuzzedDataProvider fdp(data, size); - std::string pkgName = fdp.ConsumeRandomLengthString(); - DeviceManagerImpl::GetInstance().UnRegisterPinHolderCallback(pkgName); - } - } - } +#include "device_manager_impl.h" + +namespace OHOS { +namespace DistributedHardware { - /* Fuzzer entry point */ - extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) - { - /* Run your code on data */ - OHOS::DistributedHardware::StopAuthenticateDeviceTest(data, size); - OHOS::DistributedHardware::UnBindDeviceTest(data, size); - OHOS::DistributedHardware::ShiftLNNGearTest(data, size); - OHOS::DistributedHardware::RegDevTrustChangeCallbackTest(data, size); - OHOS::DistributedHardware::GetNetworkIdByUdidTest(data, size); - OHOS::DistributedHardware::RegisterCredentialAuthStatusCallbackTest(data, size); - OHOS::DistributedHardware::GetAllTrustedDeviceListTest(data, size); - OHOS::DistributedHardware::RegisterSinkBindCallbackTest(data, size); - OHOS::DistributedHardware::GetDeviceProfileInfoListTest(data, size); - OHOS::DistributedHardware::GetDeviceIconInfoTest(data, size); - OHOS::DistributedHardware::PutDeviceProfileInfoListTest(data, size); - OHOS::DistributedHardware::GetLocalDisplayDeviceNameTest(data, size); - OHOS::DistributedHardware::GetDeviceNetworkIdListTest(data, size); - OHOS::DistributedHardware::SetLocalDeviceNameTest(data, size); - OHOS::DistributedHardware::SetRemoteDeviceNameTest(data, size); - OHOS::DistributedHardware::RestoreLocalDeviceNameTest(data, size); - OHOS::DistributedHardware::GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(data, size); - OHOS::DistributedHardware::UnRegisterPinHolderCallbackTest(data, size); - return 0; - } - \ No newline at end of file +namespace {} + +void StopAuthenticateDeviceTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().StopAuthenticateDevice(pkgName); + DeviceManagerImpl::GetInstance().OnDmServiceDied(); +} + +void UnBindDeviceTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().UnBindDevice(pkgName, deviceId); +} + +void ShiftLNNGearTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().ShiftLNNGear(pkgName); +} + +void RegDevTrustChangeCallbackTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::shared_ptr callback = nullptr; + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().RegDevTrustChangeCallback(pkgName, callback); +} + +void GetNetworkIdByUdidTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string udid = fdp.ConsumeRandomLengthString(); + std::string networkId = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().GetNetworkIdByUdid(pkgName, udid, networkId); +} + +void RegisterCredentialAuthStatusCallbackTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().RegisterCredentialAuthStatusCallback(pkgName, callback); +} + +void GetAllTrustedDeviceListTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string extra = fdp.ConsumeRandomLengthString(); + std::vector deviceList; + DeviceManagerImpl::GetInstance().GetAllTrustedDeviceList(pkgName, extra, deviceList); +} + +void RegisterSinkBindCallbackTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().RegisterSinkBindCallback(pkgName, callback); +} + +void GetDeviceProfileInfoListTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DmDeviceProfileInfoFilterOptions filterOptions; + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); +} + +void GetDeviceIconInfoTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DmDeviceProfileInfoFilterOptions filterOptions; + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().GetDeviceProfileInfoList(pkgName, filterOptions, callback); +} + +void PutDeviceProfileInfoListTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::vector deviceProfileInfoList; + DeviceManagerImpl::GetInstance().PutDeviceProfileInfoList(pkgName, deviceProfileInfoList); +} + +void GetLocalDisplayDeviceNameTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string displayName = fdp.ConsumeRandomLengthString(); + int32_t maxNameLength = fdp.ConsumeIntegral(); + DeviceManagerImpl::GetInstance().GetLocalDisplayDeviceName(pkgName, maxNameLength, displayName); +} + +void GetDeviceNetworkIdListTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(); + NetworkIdQueryFilter queryFilter; + std::vector networkIds; + DeviceManagerImpl::GetInstance().GetDeviceNetworkIdList(bundleName, queryFilter, networkIds); +} + +void SetLocalDeviceNameTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().SetLocalDeviceName(pkgName, deviceName, callback); +} + +void SetRemoteDeviceNameTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::shared_ptr callback = nullptr; + DeviceManagerImpl::GetInstance().SetRemoteDeviceName(pkgName, deviceId, deviceName, callback); +} + +void RestoreLocalDeviceNameTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().RestoreLocalDeviceName(pkgName); +} + +void GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string bundleName = fdp.ConsumeRandomLengthString(); + int32_t maxNameLength = fdp.ConsumeIntegral(); + DMLocalServiceInfo info; + DeviceManagerImpl::GetInstance().GetLocalServiceInfoByBundleNameAndPinExchangeType(bundleName, maxNameLength, info); +} + +void UnRegisterPinHolderCallbackTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + DeviceManagerImpl::GetInstance().UnRegisterPinHolderCallback(pkgName); +} + +void DeviceManagerImplFuzzTest(const uint8_t *data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + std::string pkgName = fdp.ConsumeRandomLengthString(); + std::string deviceName = fdp.ConsumeRandomLengthString(); + std::string deviceId = fdp.ConsumeRandomLengthString(); + std::string extra = fdp.ConsumeRandomLengthString(); + std::string bundleName = fdp.ConsumeRandomLengthString(); + int32_t pinExchangeType = fdp.ConsumeIntegral(); + OHOS::DistributedHardware::DmDeviceIconInfoFilterOptions filterOptions; + DMLocalServiceInfo localServiceInfo; + DmAccessCaller caller; + DmAccessCallee callee; + DMIpcCmdInterfaceCode ipcCode = REGISTER_DEVICE_MANAGER_LISTENER; + DeviceManagerImpl::GetInstance().GetLocalDeviceName(pkgName, deviceName); + DeviceManagerImpl::GetInstance().UnBindDevice(pkgName, deviceId, extra); + DeviceManagerImpl::GetInstance().UnRegisterSinkBindCallback(pkgName); + DeviceManagerImpl::GetInstance().RegisterLocalServiceInfo(localServiceInfo); + DeviceManagerImpl::GetInstance().UnRegisterLocalServiceInfo(bundleName, pinExchangeType); + DeviceManagerImpl::GetInstance().UpdateLocalServiceInfo(localServiceInfo); + DeviceManagerImpl::GetInstance().CheckAccessControl(caller, callee); + DeviceManagerImpl::GetInstance().CheckIsSameAccount(caller, callee); + DeviceManagerImpl::GetInstance().CheckSrcAccessControl(caller, callee); + DeviceManagerImpl::GetInstance().CheckSinkAccessControl(caller, callee); + DeviceManagerImpl::GetInstance().CheckSrcIsSameAccount(caller, callee); + DeviceManagerImpl::GetInstance().CheckSinkIsSameAccount(caller, callee); + DeviceManagerImpl::GetInstance().CheckAclByIpcCode(caller, callee, ipcCode); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::StopAuthenticateDeviceTest(data, size); + OHOS::DistributedHardware::UnBindDeviceTest(data, size); + OHOS::DistributedHardware::ShiftLNNGearTest(data, size); + OHOS::DistributedHardware::RegDevTrustChangeCallbackTest(data, size); + OHOS::DistributedHardware::GetNetworkIdByUdidTest(data, size); + OHOS::DistributedHardware::RegisterCredentialAuthStatusCallbackTest(data, size); + OHOS::DistributedHardware::GetAllTrustedDeviceListTest(data, size); + OHOS::DistributedHardware::RegisterSinkBindCallbackTest(data, size); + OHOS::DistributedHardware::GetDeviceProfileInfoListTest(data, size); + OHOS::DistributedHardware::GetDeviceIconInfoTest(data, size); + OHOS::DistributedHardware::PutDeviceProfileInfoListTest(data, size); + OHOS::DistributedHardware::GetLocalDisplayDeviceNameTest(data, size); + OHOS::DistributedHardware::GetDeviceNetworkIdListTest(data, size); + OHOS::DistributedHardware::SetLocalDeviceNameTest(data, size); + OHOS::DistributedHardware::SetRemoteDeviceNameTest(data, size); + OHOS::DistributedHardware::RestoreLocalDeviceNameTest(data, size); + OHOS::DistributedHardware::GetLocalServiceInfoByBundleNameAndPinExchangeTypeTest(data, size); + OHOS::DistributedHardware::UnRegisterPinHolderCallbackTest(data, size); + OHOS::DistributedHardware::DeviceManagerImplFuzzTest(data, size); + return 0; +} diff --git a/test/servicesfuzztest/BUILD.gn b/test/servicesfuzztest/BUILD.gn index 074d1cd33..e6a972d7f 100644 --- a/test/servicesfuzztest/BUILD.gn +++ b/test/servicesfuzztest/BUILD.gn @@ -28,6 +28,7 @@ group("fuzztest") { "devicenamemanagerone_fuzzer:fuzztest", "deviceprofileconnector_fuzzer:fuzztest", "devicepublish_fuzzer:fuzztest", + "dmauthattestcommon_fuzzer:fuzztest", "dmcommtool_fuzzer:fuzztest", "dmcommtooltwo_fuzzer:fuzztest", "dmtransport_fuzzer:fuzztest", diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/BUILD.gn b/test/servicesfuzztest/dmauthattestcommon_fuzzer/BUILD.gn new file mode 100644 index 000000000..0b933d849 --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/BUILD.gn @@ -0,0 +1,80 @@ +# Copyright (c) 2022-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("DmAuthAttestCommonFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/servicesfuzztest/dmauthattestcommon_fuzzer" + + include_dirs = [ + "${utils_path}/include", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include/ipc/standard", + "${servicesimpl_path}/include", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/config", + "${innerkits_path}/native_cpp/include", + "${servicesimpl_path}/include/attest", + "${utils_path}/include/kvadapter", + "${json_path}/include", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + sources = [ + "${servicesimpl_path}/src/adapter/standard/dm_adapter_manager.cpp", + "dm_auth_attest_common_fuzzer.cpp", + "${json_path}/src/json_object_cjson.cpp", + ] + + deps = [ + "${devicemanager_path}/services/implementation:devicemanagerserviceimpl", + ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"DmAuthAttestCommonFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] + + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "safwk:system_ability_fwk", + "hilog:libhilog", + ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":DmAuthAttestCommonFuzzTest" ] +} +############################################################################### diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/corpus/init b/test/servicesfuzztest/dmauthattestcommon_fuzzer/corpus/init new file mode 100644 index 000000000..9c560fe89 --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/corpus/init @@ -0,0 +1,13 @@ +# 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 diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.cpp b/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.cpp new file mode 100644 index 000000000..799eed03b --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.cpp @@ -0,0 +1,56 @@ +/* + * 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 "dm_auth_attest_common_fuzzer.h" + +#include + +#include "dm_auth_attest_common.h" + +namespace OHOS { +namespace DistributedHardware { + +void DmAuthAttestCommonFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size == 0)) { + return; + } + FuzzedDataProvider fdp(data, size); + DmCertChain* chain = new DmCertChain; + chain->cert = new DmBlob[1]; + chain->certCount = 1; + int32_t maxLen = 65535; + chain->cert[0].size = size; + if (size > 0 && size <= maxLen) { + chain->cert[0].data = new uint8_t[size]; + *chain->cert[0].data = fdp.ConsumeIntegral(); + } + std::string str_value = fdp.ConsumeRandomLengthString(); + JsonItemObject jsonItem; + jsonItem.PushBack(str_value); + AuthAttestCommon::GetInstance().SerializeDmCertChain(nullptr); + AuthAttestCommon::GetInstance().SerializeDmCertChain(chain); + AuthAttestCommon::GetInstance().FreeDmCertChain(*chain); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DmAuthAttestCommonFuzzTest(data, size); + return 0; +} diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.h b/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_fuzzer.h new file mode 100644 index 000000000..e4e5a1fff --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/dm_auth_attest_common_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 DM_AUTH_ATTEST_COMMON_FUZZ_TEST_H +#define DM_AUTH_ATTEST_COMMON_FUZZ_TEST_H + +#define FUZZ_PROJECT_NAME "dmauthattestcommon_fuzzer" + +#endif // DM_AUTH_ATTEST_COMMON_FUZZ_TEST_H diff --git a/test/servicesfuzztest/dmauthattestcommon_fuzzer/project.xml b/test/servicesfuzztest/dmauthattestcommon_fuzzer/project.xml new file mode 100644 index 000000000..500f6f414 --- /dev/null +++ b/test/servicesfuzztest/dmauthattestcommon_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp b/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp index f8b0b9354..f8d04a6bd 100644 --- a/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp +++ b/test/servicesfuzztest/dmcommtool_fuzzer/dm_comm_tool_fuzzer.cpp @@ -62,6 +62,32 @@ void DmCommToolFuzzTest(const uint8_t* data, size_t size) dmCommToolPtr_->GetDMTransportPtr(); dmCommToolPtr_->GetEventHandler(); } + +void DmCommToolFirstFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + DMCommTool::DMCommToolEventHandler dmCommToolEventHandler( + AppExecFwk::EventRunner::Create(FUZZ_PROJECT_NAME), dmCommToolPtr_); + + int32_t socketId = fdp.ConsumeIntegral(); + std::string rmtNetworkId = fdp.ConsumeRandomLengthString(); + int32_t code = fdp.ConsumeIntegral(); + std::string msg = fdp.ConsumeRandomLengthString(); + std::shared_ptr commMsg = std::make_shared(code, msg); + std::shared_ptr innrCommMsg = std::make_shared(rmtNetworkId, commMsg, socketId); + UserIdsMsg userIdsMsg; + userIdsMsg.foregroundUserIds.push_back(DATA_LEN); + dmCommToolEventHandler.ParseUserIdsMsg(innrCommMsg, userIdsMsg); + AppExecFwk::InnerEvent::Pointer event = AppExecFwk::InnerEvent::Get(commMsg->code, innrCommMsg); + dmCommToolEventHandler.ProcessEvent(event); + dmCommToolPtr_->ProcessResponseUserStopEvent(innrCommMsg); + std::string commonEventType; + EventCallback eventCallback; + dmCommToolPtr_->StartCommonEvent(commonEventType, eventCallback); +} } } @@ -70,5 +96,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::DmCommToolFuzzTest(data, size); + OHOS::DistributedHardware::DmCommToolFirstFuzzTest(data, size); return 0; } diff --git a/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp b/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp index 663947393..ec35472c8 100644 --- a/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp +++ b/test/servicesfuzztest/dmtransportmsg_fuzzer/dm_transport_msg_fuzzer.cpp @@ -86,6 +86,35 @@ void DmTransPortMsgFuzzTest(const uint8_t* data, size_t size) notifyUserIds.ToString(); cJSON_Delete(jsonObject); } + +void DmTransPortMsgFirstFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t code = fdp.ConsumeIntegral(); + std::string msg(reinterpret_cast(data), size); + std::string remoteUdid(reinterpret_cast(data), size); + const char* jsonString = R"({ + "MsgType": "0", + "userId": "12345", + "accountId": "a******3", + "peerUdids": ["u******1", "u******2"], + "peerUdid": "p******d", + "accountName": "t******t", + "syncUserIdFlag": 1, + "userIds": [ + {"type": 1, "userId": 111}, + {"type": 0, "userId": 222} + ] + })"; + cJSON* jsonObject = nullptr; + LogoutAccountMsg accountInfo; + ToJson(jsonObject, accountInfo); + FromJson(jsonObject, accountInfo); + cJSON_Delete(jsonObject); +} } } @@ -94,5 +123,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) { /* Run your code on data */ OHOS::DistributedHardware::DmTransPortMsgFuzzTest(data, size); + OHOS::DistributedHardware::DmTransPortMsgFirstFuzzTest(data, size); return 0; } -- Gitee