From be5117aadde1f7d4e6264bbde784190a69c9e76f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Fri, 25 Jul 2025 09:52:22 +0800 Subject: [PATCH 1/3] add fuzz MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- test/servicesfuzztest/BUILD.gn | 2 + .../hichainlistener_fuzzer/BUILD.gn | 94 +++ .../hichainlistener_fuzzer/corpus/init | 13 + .../hichain_listener_fuzzer.cpp | 214 +++++ .../hichain_listener_fuzzer.h | 21 + .../hichainlistener_fuzzer/project.xml | 25 + .../ipcmodelcodec_fuzzer/BUILD.gn | 90 ++ .../ipcmodelcodec_fuzzer/corpus/init | 13 + .../ipc_model_codec_fuzzer.cpp | 788 ++++++++++++++++++ .../ipc_model_codec_fuzzer.h | 21 + .../ipcmodelcodec_fuzzer/project.xml | 25 + 11 files changed, 1306 insertions(+) create mode 100644 test/servicesfuzztest/hichainlistener_fuzzer/BUILD.gn create mode 100644 test/servicesfuzztest/hichainlistener_fuzzer/corpus/init create mode 100644 test/servicesfuzztest/hichainlistener_fuzzer/hichain_listener_fuzzer.cpp create mode 100644 test/servicesfuzztest/hichainlistener_fuzzer/hichain_listener_fuzzer.h create mode 100644 test/servicesfuzztest/hichainlistener_fuzzer/project.xml create mode 100644 test/servicesfuzztest/ipcmodelcodec_fuzzer/BUILD.gn create mode 100644 test/servicesfuzztest/ipcmodelcodec_fuzzer/corpus/init create mode 100644 test/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.cpp create mode 100644 test/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.h create mode 100644 test/servicesfuzztest/ipcmodelcodec_fuzzer/project.xml diff --git a/test/servicesfuzztest/BUILD.gn b/test/servicesfuzztest/BUILD.gn index e6a972d7f..30bf959df 100644 --- a/test/servicesfuzztest/BUILD.gn +++ b/test/servicesfuzztest/BUILD.gn @@ -38,9 +38,11 @@ group("fuzztest") { "gettrusteddevicelistservice_fuzzer:fuzztest", "getudidbynetworkid_fuzzer:fuzztest", "getuuidbynetworkid_fuzzer:fuzztest", + "hichainlistener_fuzzer:fuzztest", "initdevicemanager_fuzzer:fuzztest", "ipcclientmanager_fuzzer:fuzztest", "ipccmdregister_fuzzer:fuzztest", + "ipcmodelcodec_fuzzer:fuzztest", "ipcserverclientproxy_fuzzer:fuzztest", "ipcserverlistener_fuzzer:fuzztest", "ipcserverstub_fuzzer:fuzztest", diff --git a/test/servicesfuzztest/hichainlistener_fuzzer/BUILD.gn b/test/servicesfuzztest/hichainlistener_fuzzer/BUILD.gn new file mode 100644 index 000000000..9af74300d --- /dev/null +++ b/test/servicesfuzztest/hichainlistener_fuzzer/BUILD.gn @@ -0,0 +1,94 @@ +# 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("HiChainListenerFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/servicesfuzztest/hichainlistener_fuzzer" + + include_dirs = [ + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "${common_path}/include/ipc/standard", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${servicesimpl_path}/include/dependency/timer", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/authentication", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include", + "${services_path}/include/hichain", + "${servicesimpl_path}/include/discovery", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/deviceinfo", + "${servicesimpl_path}/include/devicestate", + "${devicemanager_path}/test/unittest/mock", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/config", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "hichain_listener_fuzzer.cpp" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"HiChainListenerFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] + + deps = [ + "${devicemanager_path}/services/service:devicemanagerservicetest", + "${utils_path}:devicemanagerutilstest", + "${json_path}:devicemanagerjson", + ] + + external_deps = [ + "cJSON:cjson", + "c_utils:utils", + "device_auth:deviceauth_sdk", + "ipc:ipc_core", + "ipc:ipc_single", + "napi:ace_napi", + "safwk:system_ability_fwk", + ] + + public_deps = [ "${utils_path}:devicemanagerutilstest" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":HiChainListenerFuzzTest" ] +} +############################################################################### diff --git a/test/servicesfuzztest/hichainlistener_fuzzer/corpus/init b/test/servicesfuzztest/hichainlistener_fuzzer/corpus/init new file mode 100644 index 000000000..8f37f0925 --- /dev/null +++ b/test/servicesfuzztest/hichainlistener_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/servicesfuzztest/hichainlistener_fuzzer/hichain_listener_fuzzer.cpp b/test/servicesfuzztest/hichainlistener_fuzzer/hichain_listener_fuzzer.cpp new file mode 100644 index 000000000..883410a94 --- /dev/null +++ b/test/servicesfuzztest/hichainlistener_fuzzer/hichain_listener_fuzzer.cpp @@ -0,0 +1,214 @@ +/* + * 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 "hichain_listener_fuzzer.h" + +#include + +#include "hichain_listener.h" + +namespace OHOS { +namespace DistributedHardware { +constexpr size_t MAX_STRING_LENGTH = 64; +void FromJsonFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) * 2 + MAX_STRING_LENGTH; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + JsonObject jsonObject; + if (fdp.ConsumeBool()) { + jsonObject[FIELD_GROUP_TYPE] = fdp.ConsumeIntegral(); + } + if (fdp.ConsumeBool()) { + jsonObject[FIELD_USER_ID] = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + } + if (fdp.ConsumeBool()) { + jsonObject[FIELD_OS_ACCOUNT_ID] = fdp.ConsumeIntegral(); + } + + GroupInformation groupInfo; + FromJson(jsonObject, groupInfo); +} + +void FromJsonInfoFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) * 2 + MAX_STRING_LENGTH * 4; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + JsonObject jsonObject; + jsonObject[FIELD_GROUP_NAME] = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + jsonObject[FIELD_GROUP_ID] = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + jsonObject[FIELD_GROUP_OWNER] = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + jsonObject[FIELD_GROUP_TYPE] = fdp.ConsumeIntegral(); + jsonObject[FIELD_GROUP_VISIBILITY] = fdp.ConsumeIntegral(); + jsonObject[FIELD_USER_ID] = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + + GroupsInfo groupInfo; + FromJson(jsonObject, groupInfo); +} + +void RegisterDataChangeCbFuzzTest(const uint8_t* data, size_t size) +{ + (void)data; + (void)size; + + std::shared_ptr hiChainListener = std::make_shared(); + hiChainListener->deviceGroupManager_ = nullptr; + hiChainListener->RegisterDataChangeCb(); +} + +void RegisterCredentialCbFuzzTest(const uint8_t* data, size_t size) +{ + (void)data; + (void)size; + + std::shared_ptr hiChainListener = std::make_shared(); + hiChainListener->credManager_ = nullptr; + hiChainListener->RegisterCredentialCb(); +} + +void OnHichainDeviceUnBoundFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size == 0) { + return; + } + FuzzedDataProvider fdp(data, size); + + std::shared_ptr hiChainListener = std::make_shared(); + + uint32_t maxLength = 65536; + std::string peerUdid = fdp.ConsumeRandomLengthString(size > maxLength ? maxLength : size); + std::string groupInfo = fdp.ConsumeRandomLengthString(size > maxLength ? maxLength : size); + hiChainListener->OnHichainDeviceUnBound(peerUdid.c_str(), groupInfo.c_str()); + + hiChainListener->OnHichainDeviceUnBound(nullptr, groupInfo.c_str()); + + uint32_t outMaxLength = 65537; + std::string longPeerUdid(outMaxLength, 'a'); + std::string longGroupInfo(outMaxLength, 'b'); + hiChainListener->OnHichainDeviceUnBound(longPeerUdid.c_str(), longGroupInfo.c_str()); +} + +void OnCredentialDeletedFuzzTest(const uint8_t* data, size_t size) +{ + if (data == nullptr || size == 0) { + return; + } + FuzzedDataProvider fdp(data, size); + + std::shared_ptr hiChainListener = std::make_shared(); + + uint32_t maxLength = 65536; + std::string credId = fdp.ConsumeRandomLengthString(size > maxLength ? maxLength : size); + std::string credInfo = fdp.ConsumeRandomLengthString(size > maxLength ? maxLength : size); + hiChainListener->OnCredentialDeleted(credId.c_str(), credInfo.c_str()); + + hiChainListener->OnCredentialDeleted(nullptr, credInfo.c_str()); + + uint32_t outMaxLength = 65537; + std::string longCredId(outMaxLength, 'a'); + std::string longCredInfo(outMaxLength, 'b'); + hiChainListener->OnCredentialDeleted(longCredId.c_str(), longCredInfo.c_str()); +} + +void DeleteAllGroupFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(size_t) + MAX_STRING_LENGTH)) { + return; + } + FuzzedDataProvider fdp(data, size); + + std::string localUdid = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + + size_t minUserIdCount = 0; + size_t maxUserIdCount = 10; + size_t userIdCount = fdp.ConsumeIntegralInRange(minUserIdCount, maxUserIdCount); + std::vector backgroundUserIds; + for (size_t i = 0; i < userIdCount; ++i) { + backgroundUserIds.push_back(fdp.ConsumeIntegral()); + } + + std::shared_ptr hiChainListener = std::make_shared(); + hiChainListener->DeleteAllGroup(localUdid, backgroundUserIds); +} + +void GetRelatedGroupsFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t) + MAX_STRING_LENGTH)) { + return; + } + FuzzedDataProvider fdp(data, size); + + int32_t userId = fdp.ConsumeIntegral(); + std::string deviceId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + std::vector groupList; + + std::shared_ptr hiChainListener = std::make_shared(); + hiChainListener->GetRelatedGroups(userId, deviceId, groupList); +} + +void GetRelatedGroupsExtFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t) + MAX_STRING_LENGTH)) { + return; + } + FuzzedDataProvider fdp(data, size); + + int32_t userId = fdp.ConsumeIntegral(); + std::string deviceId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + std::vector groupList; + + std::shared_ptr hiChainListener = std::make_shared(); + hiChainListener->GetRelatedGroupsExt(userId, deviceId, groupList); +} + +void DeleteCredentialFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(int32_t) + MAX_STRING_LENGTH)) { + return; + } + FuzzedDataProvider fdp(data, size); + + int32_t osAccountId = fdp.ConsumeIntegral(); + std::string credId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + + std::shared_ptr hiChainListener = std::make_shared(); + hiChainListener->credManager_ = nullptr; + hiChainListener->DeleteCredential(osAccountId, credId); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::FromJsonFuzzTest(data, size); + OHOS::DistributedHardware::FromJsonInfoFuzzTest(data, size); + OHOS::DistributedHardware::RegisterDataChangeCbFuzzTest(data, size); + OHOS::DistributedHardware::RegisterCredentialCbFuzzTest(data, size); + OHOS::DistributedHardware::OnHichainDeviceUnBoundFuzzTest(data, size); + OHOS::DistributedHardware::OnCredentialDeletedFuzzTest(data, size); + OHOS::DistributedHardware::DeleteAllGroupFuzzTest(data, size); + OHOS::DistributedHardware::GetRelatedGroupsFuzzTest(data, size); + OHOS::DistributedHardware::GetRelatedGroupsExtFuzzTest(data, size); + OHOS::DistributedHardware::DeleteCredentialFuzzTest(data, size); + return 0; +} diff --git a/test/servicesfuzztest/hichainlistener_fuzzer/hichain_listener_fuzzer.h b/test/servicesfuzztest/hichainlistener_fuzzer/hichain_listener_fuzzer.h new file mode 100644 index 000000000..1889ae344 --- /dev/null +++ b/test/servicesfuzztest/hichainlistener_fuzzer/hichain_listener_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 HICHAIN_LISTENER_FUZZER_H +#define HICHAIN_LISTENER_FUZZER_H + +#define FUZZ_PROJECT_NAME "hichain_listener_fuzzer" + +#endif // HI_CHAIN_LISTENER_FUZZER_H \ No newline at end of file diff --git a/test/servicesfuzztest/hichainlistener_fuzzer/project.xml b/test/servicesfuzztest/hichainlistener_fuzzer/project.xml new file mode 100644 index 000000000..500f6f414 --- /dev/null +++ b/test/servicesfuzztest/hichainlistener_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file diff --git a/test/servicesfuzztest/ipcmodelcodec_fuzzer/BUILD.gn b/test/servicesfuzztest/ipcmodelcodec_fuzzer/BUILD.gn new file mode 100644 index 000000000..2f9a6ef53 --- /dev/null +++ b/test/servicesfuzztest/ipcmodelcodec_fuzzer/BUILD.gn @@ -0,0 +1,90 @@ +# 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("IpcModelCodecFuzzTest") { + module_out_path = fuzz_test_output_path + fuzz_config_file = + "${devicemanager_path}/test/servicesfuzztest/ipcmodelcodec_fuzzer" + + include_dirs = [ + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include", + "${innerkits_path}/native_cpp/include/ipc/standard", + "${innerkits_path}/native_cpp/include/ipc", + "${innerkits_path}/native_cpp/include/notify", + "${common_path}/include/ipc/standard", + "${common_path}/include", + "${common_path}/include/ipc", + "${common_path}/include/ipc/model", + "${utils_path}/include", + "${utils_path}/include/ipc/standard", + "${servicesimpl_path}/include/dependency/timer", + "${servicesimpl_path}/include/dependency/softbus", + "${servicesimpl_path}/include/authentication", + "${servicesimpl_path}/include/adapter", + "${servicesimpl_path}/include", + "${services_path}/include/ipc/standard", + "${servicesimpl_path}/include/discovery", + "${servicesimpl_path}/include/dependency/hichain", + "${servicesimpl_path}/include/deviceinfo", + "${servicesimpl_path}/include/devicestate", + "${devicemanager_path}/test/unittest/mock", + "${servicesimpl_path}/include/ability", + "${servicesimpl_path}/include/config", + ] + + cflags = [ + "-g", + "-O0", + "-Dprivate=public", + "-Dprotected=public", + "-Werror", + "-Wno-unused-variable", + "-fno-omit-frame-pointer", + ] + + sources = [ "ipc_model_codec_fuzzer.cpp" ] + + defines = [ + "HI_LOG_ENABLE", + "DH_LOG_TAG=\"IpcModelCodecFuzzTest\"", + "LOG_DOMAIN=0xD004110", + ] + + deps = [ "${innerkits_path}/native_cpp:devicemanagersdk" ] + + external_deps = [ + "c_utils:utils", + "device_auth:deviceauth_sdk", + "ipc:ipc_core", + "ipc:ipc_single", + "napi:ace_napi", + "safwk:system_ability_fwk", + ] + + public_deps = [ "${utils_path}:devicemanagerutilstest" ] +} + +############################################################################### +group("fuzztest") { + testonly = true + + deps = [ ":IpcModelCodecFuzzTest" ] +} +############################################################################### diff --git a/test/servicesfuzztest/ipcmodelcodec_fuzzer/corpus/init b/test/servicesfuzztest/ipcmodelcodec_fuzzer/corpus/init new file mode 100644 index 000000000..8f37f0925 --- /dev/null +++ b/test/servicesfuzztest/ipcmodelcodec_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/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.cpp b/test/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.cpp new file mode 100644 index 000000000..2ea4c10fe --- /dev/null +++ b/test/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.cpp @@ -0,0 +1,788 @@ +/* + * 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 "ipc_model_codec_fuzzer.h" + +#include + +#include "ipc_model_codec.h" + + +namespace OHOS { +namespace DistributedHardware { +constexpr size_t MAX_STRING_LENGTH = 64; +void DecodeDmDeviceBasicInfoFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(uint16_t) + MAX_STRING_LENGTH * 4; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + MessageParcel parcel; + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteUint16(fdp.ConsumeIntegral()); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + + DmDeviceBasicInfo devInfo; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodeDmDeviceBasicInfo(parcel, devInfo); +} + +void EncodePeerTargetIdFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(uint16_t) + MAX_STRING_LENGTH * 4; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + PeerTargetId targetId; + targetId.deviceId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + targetId.brMac = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + targetId.bleMac = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + targetId.wifiIp = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + targetId.wifiPort = fdp.ConsumeIntegral(); + + MessageParcel parcel; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodePeerTargetId(targetId, parcel); +} + +void DecodePeerTargetIdFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(uint16_t) + MAX_STRING_LENGTH * 4; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + MessageParcel parcel; + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteUint16(fdp.ConsumeIntegral()); + + PeerTargetId targetId; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodePeerTargetId(parcel, targetId); +} + +void EncodeDmAccessCallerFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) + sizeof(uint64_t) + MAX_STRING_LENGTH * 4; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + DmAccessCaller caller; + caller.accountId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + caller.pkgName = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + caller.networkId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + caller.userId = fdp.ConsumeIntegral(); + caller.tokenId = fdp.ConsumeIntegral(); + caller.extra = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + + MessageParcel parcel; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodeDmAccessCaller(caller, parcel); +} + +void EncodeDmAccessCalleeFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) + sizeof(uint64_t) + MAX_STRING_LENGTH * 5; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + DmAccessCallee callee; + callee.accountId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + callee.networkId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + callee.peerId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + callee.pkgName = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + callee.userId = fdp.ConsumeIntegral(); + callee.extra = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + callee.tokenId = fdp.ConsumeIntegral(); + + MessageParcel parcel; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodeDmAccessCallee(callee, parcel); +} + +void DecodeDmDeviceProfileInfoFilterOptionsFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t) + sizeof(uint32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + + MessageParcel parcel; + parcel.WriteBool(fdp.ConsumeBool()); + uint32_t minRangeSize = 0; + uint32_t middleRangeSize = 500; + uint32_t maxRangeSize = 1000; + uint32_t listSize = fdp.ConsumeIntegralInRange(middleRangeSize, maxRangeSize); + parcel.WriteUint32(listSize); + + DmDeviceProfileInfoFilterOptions filterOptions; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodeDmDeviceProfileInfoFilterOptions(parcel, filterOptions); + + listSize = fdp.ConsumeIntegralInRange(minRangeSize, middleRangeSize); + parcel.WriteUint32(listSize); + ipcModelCodec->DecodeDmDeviceProfileInfoFilterOptions(parcel, filterOptions); +} + +void EncodeDmDeviceProfileInfoFilterOptionsFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t) + MAX_STRING_LENGTH)) { + return; + } + FuzzedDataProvider fdp(data, size); + + DmDeviceProfileInfoFilterOptions filterOptions; + filterOptions.isCloud = fdp.ConsumeBool(); + uint32_t minRangeSize = 0; + uint32_t maxRangeSize = 100; + uint32_t listSize = fdp.ConsumeIntegralInRange(minRangeSize, maxRangeSize); + for (uint32_t i = 0; i < listSize; ++i) { + filterOptions.deviceIdList.emplace_back(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + } + MessageParcel parcel; + + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodeDmDeviceProfileInfoFilterOptions(filterOptions, parcel); +} + +void DecodeDmServiceProfileInfoFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) + MAX_STRING_LENGTH * 5; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + MessageParcel parcel; + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + int32_t minRangeSize = 0; + int32_t maxRangeSize = 100; + int32_t num = fdp.ConsumeIntegralInRange(minRangeSize, maxRangeSize); + parcel.WriteInt32(num); + for (int32_t i = 0; i < num; ++i) { + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + } + DmServiceProfileInfo svrInfo; + + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodeDmServiceProfileInfo(parcel, svrInfo); +} + +void DecodeDmServiceProfileInfosFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) * 2 + MAX_STRING_LENGTH * 5; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + MessageParcel parcel; + int32_t minRangeSize = 0; + int32_t middleRangeSize = 50; + int32_t maxRangeSize = 100; + int32_t svrNum = fdp.ConsumeIntegralInRange(minRangeSize, maxRangeSize); + parcel.WriteInt32(svrNum); + for (int32_t i = 0; i < svrNum; ++i) { + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + int32_t num = fdp.ConsumeIntegralInRange(minRangeSize, middleRangeSize); + parcel.WriteInt32(num); + for (int32_t j = 0; j < num; ++j) { + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + } + } + std::vector svrInfos; + + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodeDmServiceProfileInfos(parcel, svrInfos); +} + +void DecodeDmDeviceProfileInfoFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) * 2 + MAX_STRING_LENGTH * 22; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + MessageParcel parcel; + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteBool(fdp.ConsumeBool()); + int32_t serviceCount = 10; + parcel.WriteInt32(serviceCount); + for (int32_t i = 0; i < serviceCount; ++i) { + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + int32_t dataCount = 5; + parcel.WriteInt32(dataCount); + for (int32_t j = 0; j < dataCount; ++j) { + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + } + } + DmDeviceProfileInfo devInfo; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodeDmDeviceProfileInfo(parcel, devInfo); +} + +void EncodeDmServiceProfileInfoFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) + MAX_STRING_LENGTH * 5; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + DmServiceProfileInfo svrInfo; + svrInfo.deviceId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + svrInfo.serviceId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + svrInfo.serviceType = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + int32_t minRangeSize = 0; + int32_t maxRangeSize = 100; + int32_t dataSize = fdp.ConsumeIntegralInRange(minRangeSize, maxRangeSize); + for (int32_t i = 0; i < dataSize; ++i) { + std::string key = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + std::string value = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + svrInfo.data[key] = value; + } + MessageParcel parcel; + + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodeDmServiceProfileInfo(svrInfo, parcel); +} + +void EncodeDmServiceProfileInfosFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) * 2 + MAX_STRING_LENGTH * 5; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + int32_t minRangeSize = 0; + int32_t middleRangeSize = 50; + int32_t maxRangeSize = 100; + std::vector svrInfos; + int32_t listSize = fdp.ConsumeIntegralInRange(minRangeSize, maxRangeSize); + for (int32_t i = 0; i < listSize; ++i) { + DmServiceProfileInfo svrInfo; + svrInfo.deviceId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + svrInfo.serviceId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + svrInfo.serviceType = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + + int32_t dataSize = fdp.ConsumeIntegralInRange(minRangeSize, middleRangeSize); + for (int32_t j = 0; j < dataSize; ++j) { + std::string key = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + std::string value = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + svrInfo.data[key] = value; + } + svrInfos.emplace_back(svrInfo); + } + MessageParcel parcel; + + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodeDmServiceProfileInfos(svrInfos, parcel); +} + +void EncodeDmDeviceProfileInfoFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) * 2 + MAX_STRING_LENGTH * 22; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + DmDeviceProfileInfo devInfo; + devInfo.deviceId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.deviceSn = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.mac = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.model = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.internalModel = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.deviceType = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.manufacturer = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.deviceName = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.productName = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.productId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.subProductId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.sdkVersion = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.bleMac = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.sleMac = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.firmwareVersion = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.hardwareVersion = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.softwareVersion = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.protocolType = fdp.ConsumeIntegral(); + devInfo.setupType = fdp.ConsumeIntegral(); + devInfo.wiseDeviceId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.wiseUserId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.registerTime = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.modifyTime = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.shareTime = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + devInfo.isLocalDevice = fdp.ConsumeBool(); + int32_t serviceCount = 10; + for (int32_t i = 0; i < serviceCount; ++i) { + DmServiceProfileInfo serviceInfo; + serviceInfo.deviceId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfo.serviceId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfo.serviceType = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + int32_t dataCount = 5; + for (int32_t j = 0; j < dataCount; ++j) { + std::string key = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + std::string value = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfo.data[key] = value; + } + devInfo.services.emplace_back(serviceInfo); + } + MessageParcel parcel; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodeDmDeviceProfileInfo(devInfo, parcel); +} + +void GetDeviceIconInfoUniqueKeyFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = MAX_STRING_LENGTH * 5; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + DmDeviceIconInfoFilterOptions iconFilter; + iconFilter.productId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + iconFilter.subProductId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + iconFilter.internalModel = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + iconFilter.imageType = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + iconFilter.specName = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->GetDeviceIconInfoUniqueKey(iconFilter); +} + +void GetDeviceIconInfoFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = MAX_STRING_LENGTH * 5; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + DmDeviceIconInfo iconInfo; + iconInfo.productId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + iconInfo.subProductId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + iconInfo.internalModel = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + iconInfo.imageType = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + iconInfo.specName = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->GetDeviceIconInfoUniqueKey(iconInfo); +} + +void DecodeDmDeviceIconInfoFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) + sizeof(uint8_t) + MAX_STRING_LENGTH * 7; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + MessageParcel parcel; + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + + int32_t minRangeLength = 0; + int32_t maxRangeLength = 100; + int32_t iconLength = fdp.ConsumeIntegralInRange(minRangeLength, maxRangeLength); + parcel.WriteInt32(iconLength); + if (iconLength > 0) { + std::vector iconData = fdp.ConsumeBytes(iconLength); + parcel.WriteRawData(iconData.data(), iconData.size()); + } + DmDeviceIconInfo deviceIconInfo; + + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodeDmDeviceIconInfo(parcel, deviceIconInfo); +} + +void EncodeDmDeviceIconInfoFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) + sizeof(uint8_t) + MAX_STRING_LENGTH * 7; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + DmDeviceIconInfo deviceIconInfo; + deviceIconInfo.productId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + deviceIconInfo.subProductId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + deviceIconInfo.internalModel = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + deviceIconInfo.imageType = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + deviceIconInfo.specName = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + deviceIconInfo.version = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + deviceIconInfo.url = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + + int32_t minRangeLength = 0; + int32_t maxRangeLength = 100; + int32_t iconLength = fdp.ConsumeIntegralInRange(minRangeLength, maxRangeLength); + deviceIconInfo.icon = fdp.ConsumeBytes(iconLength); + + MessageParcel parcel; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodeDmDeviceIconInfo(deviceIconInfo, parcel); +} + +void DecodeDmDeviceIconInfoFilterOptionsFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = MAX_STRING_LENGTH * 5; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + MessageParcel parcel; + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + + DmDeviceIconInfoFilterOptions filterOptions; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodeDmDeviceIconInfoFilterOptions(parcel, filterOptions); +} + +void EncodeDmDeviceIconInfoFilterOptionsFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = MAX_STRING_LENGTH * 5; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + DmDeviceIconInfoFilterOptions filterOptions; + filterOptions.productId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + filterOptions.subProductId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + filterOptions.internalModel = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + filterOptions.imageType = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + filterOptions.specName = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + + MessageParcel parcel; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodeDmDeviceIconInfoFilterOptions(filterOptions, parcel); +} + +void DecodeDmDeviceInfoFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) * 3 + sizeof(uint16_t) + MAX_STRING_LENGTH * 4; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + MessageParcel parcel; + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteUint16(fdp.ConsumeIntegral()); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + + DmDeviceInfo devInfo; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodeDmDeviceInfo(parcel, devInfo); +} + +void EncodeLocalServiceInfoFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) * 3 + MAX_STRING_LENGTH * 4; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + DMLocalServiceInfo serviceInfo; + serviceInfo.bundleName = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfo.authBoxType = fdp.ConsumeIntegral(); + serviceInfo.authType = fdp.ConsumeIntegral(); + serviceInfo.pinExchangeType = fdp.ConsumeIntegral(); + serviceInfo.pinCode = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfo.description = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfo.extraInfo = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + + MessageParcel parcel; + + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodeLocalServiceInfo(serviceInfo, parcel); +} + +void EncodeLocalServiceInfosFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) * 6 + sizeof(uint32_t) + MAX_STRING_LENGTH * 4; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + uint32_t minRangeSize = 0; + uint32_t maxRangeSize = 100; + std::vector serviceInfos; + uint32_t listSize = fdp.ConsumeIntegralInRange(minRangeSize, maxRangeSize); + for (uint32_t i = 0; i < listSize; ++i) { + DMLocalServiceInfo serviceInfo; + serviceInfo.bundleName = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfo.authBoxType = fdp.ConsumeIntegral(); + serviceInfo.authType = fdp.ConsumeIntegral(); + serviceInfo.pinExchangeType = fdp.ConsumeIntegral(); + serviceInfo.pinCode = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfo.description = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfo.extraInfo = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfos.emplace_back(serviceInfo); + } + MessageParcel parcel; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodeLocalServiceInfos(serviceInfos, parcel); + serviceInfos.clear(); + uint32_t outListSize = 1001; + for (uint32_t i = 0; i < outListSize; ++i) { + DMLocalServiceInfo serviceInfo; + serviceInfo.bundleName = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfo.authBoxType = fdp.ConsumeIntegral(); + serviceInfo.authType = fdp.ConsumeIntegral(); + serviceInfo.pinExchangeType = fdp.ConsumeIntegral(); + serviceInfo.pinCode = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfo.description = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfo.extraInfo = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + serviceInfos.emplace_back(serviceInfo); + } + ipcModelCodec->EncodeLocalServiceInfos(serviceInfos, parcel); +} + +void DecodeLocalServiceInfoFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) * 3 + MAX_STRING_LENGTH * 4; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + MessageParcel parcel; + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + + DMLocalServiceInfo serviceInfo; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodeLocalServiceInfo(parcel, serviceInfo); +} + +void DecodeLocalServiceInfosFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) * 3 + sizeof(uint32_t) + MAX_STRING_LENGTH * 4; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + uint32_t minRangeSize = 0; + uint32_t maxRangeSize = 100; + MessageParcel parcel; + uint32_t num = fdp.ConsumeIntegralInRange(minRangeSize, maxRangeSize); + parcel.WriteUint32(num); + for (uint32_t i = 0; i < num; ++i) { + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + } + + std::vector serviceInfos; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodeLocalServiceInfos(parcel, serviceInfos); +} + +void EncodeNetworkIdQueryFilterFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) + MAX_STRING_LENGTH * 4; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + NetworkIdQueryFilter queryFilter; + queryFilter.wiseDeviceId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + queryFilter.onlineStatus = fdp.ConsumeIntegral(); + queryFilter.deviceType = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + queryFilter.deviceProductId = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + queryFilter.deviceModel = fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH); + + MessageParcel parcel; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodeNetworkIdQueryFilter(queryFilter, parcel); +} + +void DecodeNetworkIdQueryFilterFuzzTest(const uint8_t* data, size_t size) +{ + size_t requiredSize = sizeof(int32_t) + MAX_STRING_LENGTH * 4; + if ((data == nullptr) || (size < requiredSize)) { + return; + } + FuzzedDataProvider fdp(data, size); + + MessageParcel parcel; + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + + NetworkIdQueryFilter queryFilter; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodeNetworkIdQueryFilter(parcel, queryFilter); +} + +void EncodeStringVectorFuzzTest(const uint8_t* data, size_t size) +{ + if ((data == nullptr) || (size < sizeof(uint32_t))) { + return; + } + FuzzedDataProvider fdp(data, size); + uint32_t minRangeSize = 0; + uint32_t maxRangeSize = 100; + + std::vector vec; + uint32_t listSize = fdp.ConsumeIntegralInRange(minRangeSize, maxRangeSize); + for (uint32_t i = 0; i < listSize; ++i) { + vec.emplace_back(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + } + MessageParcel parcel; + + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->EncodeStringVector(vec, parcel); +} + +void DecodeStringVectorFuzzTest(const uint8_t* data, size_t size) +{ + size_t count = 2; + if ((data == nullptr) || (size < sizeof(uint32_t) * count)) { + return; + } + FuzzedDataProvider fdp(data, size); + + uint32_t minRangeSize = 0; + uint32_t maxRangeSize = 1000; + MessageParcel parcel; + uint32_t num = fdp.ConsumeIntegralInRange(minRangeSize, maxRangeSize); + parcel.WriteUint32(num); + for (uint32_t i = 0; i < num; ++i) { + parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); + } + + std::vector vec; + std::shared_ptr ipcModelCodec = std::make_shared(); + ipcModelCodec->DecodeStringVector(parcel, vec); + + uint32_t outMinRangeSize = 1001; + uint32_t outMaxRangeSize = 2000; + uint32_t invalidNum = fdp.ConsumeIntegralInRange(outMinRangeSize, outMaxRangeSize); + MessageParcel invalidParcel; + parcel.WriteUint32(invalidNum); + ipcModelCodec->DecodeStringVector(invalidParcel, vec); +} +} +} + +/* Fuzzer entry point */ +extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) +{ + /* Run your code on data */ + OHOS::DistributedHardware::DecodeDmDeviceBasicInfoFuzzTest(data, size); + OHOS::DistributedHardware::EncodePeerTargetIdFuzzTest(data, size); + OHOS::DistributedHardware::DecodePeerTargetIdFuzzTest(data, size); + OHOS::DistributedHardware::EncodeDmAccessCallerFuzzTest(data, size); + OHOS::DistributedHardware::EncodeDmAccessCalleeFuzzTest(data, size); + OHOS::DistributedHardware::DecodeDmDeviceProfileInfoFilterOptionsFuzzTest(data, size); + OHOS::DistributedHardware::EncodeDmDeviceProfileInfoFilterOptionsFuzzTest(data, size); + OHOS::DistributedHardware::DecodeDmServiceProfileInfoFuzzTest(data, size); + OHOS::DistributedHardware::DecodeDmServiceProfileInfosFuzzTest(data, size); + OHOS::DistributedHardware::DecodeDmDeviceProfileInfoFuzzTest(data, size); + OHOS::DistributedHardware::EncodeDmServiceProfileInfoFuzzTest(data, size); + OHOS::DistributedHardware::EncodeDmServiceProfileInfosFuzzTest(data, size); + OHOS::DistributedHardware::EncodeDmDeviceProfileInfoFuzzTest(data, size); + OHOS::DistributedHardware::GetDeviceIconInfoUniqueKeyFuzzTest(data, size); + OHOS::DistributedHardware::GetDeviceIconInfoFuzzTest(data, size); + OHOS::DistributedHardware::DecodeDmDeviceIconInfoFuzzTest(data, size); + OHOS::DistributedHardware::EncodeDmDeviceIconInfoFuzzTest(data, size); + OHOS::DistributedHardware::DecodeDmDeviceIconInfoFilterOptionsFuzzTest(data, size); + OHOS::DistributedHardware::EncodeDmDeviceIconInfoFilterOptionsFuzzTest(data, size); + OHOS::DistributedHardware::DecodeDmDeviceInfoFuzzTest(data, size); + OHOS::DistributedHardware::EncodeLocalServiceInfoFuzzTest(data, size); + OHOS::DistributedHardware::EncodeLocalServiceInfosFuzzTest(data, size); + OHOS::DistributedHardware::DecodeLocalServiceInfoFuzzTest(data, size); + OHOS::DistributedHardware::DecodeLocalServiceInfosFuzzTest(data, size); + OHOS::DistributedHardware::EncodeNetworkIdQueryFilterFuzzTest(data, size); + OHOS::DistributedHardware::DecodeNetworkIdQueryFilterFuzzTest(data, size); + OHOS::DistributedHardware::EncodeStringVectorFuzzTest(data, size); + OHOS::DistributedHardware::DecodeStringVectorFuzzTest(data, size); + return 0; +} diff --git a/test/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.h b/test/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.h new file mode 100644 index 000000000..f27938b11 --- /dev/null +++ b/test/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_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 IPC_MODEL_CODEC_FUZZER_H +#define IPC_MODEL_CODEC_FUZZER_H + +#define FUZZ_PROJECT_NAME "ipcmodelcodec_fuzzer" + +#endif // IPC_MODEL_CODEC_FUZZER_H \ No newline at end of file diff --git a/test/servicesfuzztest/ipcmodelcodec_fuzzer/project.xml b/test/servicesfuzztest/ipcmodelcodec_fuzzer/project.xml new file mode 100644 index 000000000..500f6f414 --- /dev/null +++ b/test/servicesfuzztest/ipcmodelcodec_fuzzer/project.xml @@ -0,0 +1,25 @@ + + + + + + 1000 + + 300 + + 4096 + + \ No newline at end of file -- Gitee From 926f5e2c2db777e080e19df84497e31292696b32 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Fri, 25 Jul 2025 02:41:43 +0000 Subject: [PATCH 2/3] update test/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.cpp. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.cpp b/test/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.cpp index 2ea4c10fe..413d2fd01 100644 --- a/test/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.cpp +++ b/test/servicesfuzztest/ipcmodelcodec_fuzzer/ipc_model_codec_fuzzer.cpp @@ -649,7 +649,7 @@ void DecodeLocalServiceInfosFuzzTest(const uint8_t* data, size_t size) for (uint32_t i = 0; i < num; ++i) { parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); parcel.WriteInt32(fdp.ConsumeIntegral()); - parcel.WriteInt32(fdp.ConsumeIntegral()); + parcel.WriteInt32(fdp.ConsumeIntegral()); parcel.WriteInt32(fdp.ConsumeIntegral()); parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); parcel.WriteString(fdp.ConsumeRandomLengthString(MAX_STRING_LENGTH)); -- Gitee From 8350a3718360e850cc7e99e1104bba47517062de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=BC=A0=E9=9B=B7?= Date: Mon, 28 Jul 2025 09:24:11 +0800 Subject: [PATCH 3/3] modify fuzz code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 张雷 --- .../service/src/hichain/hichain_listener.cpp | 2 ++ .../hichain_listener_fuzzer.cpp | 22 ------------------- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/services/service/src/hichain/hichain_listener.cpp b/services/service/src/hichain/hichain_listener.cpp index 499cc6843..ebb72bea9 100644 --- a/services/service/src/hichain/hichain_listener.cpp +++ b/services/service/src/hichain/hichain_listener.cpp @@ -105,6 +105,7 @@ HichainListener::~HichainListener() DestroyDeviceAuthService(); } +//LCOV_EXCL_START void HichainListener::RegisterDataChangeCb() { LOGI("start"); @@ -134,6 +135,7 @@ void HichainListener::RegisterCredentialCb() } LOGI("success!"); } +//LCOV_EXCL_STOP void HichainListener::OnHichainDeviceUnBound(const char *peerUdid, const char *groupInfo) { diff --git a/test/servicesfuzztest/hichainlistener_fuzzer/hichain_listener_fuzzer.cpp b/test/servicesfuzztest/hichainlistener_fuzzer/hichain_listener_fuzzer.cpp index 883410a94..0f5936a35 100644 --- a/test/servicesfuzztest/hichainlistener_fuzzer/hichain_listener_fuzzer.cpp +++ b/test/servicesfuzztest/hichainlistener_fuzzer/hichain_listener_fuzzer.cpp @@ -64,26 +64,6 @@ void FromJsonInfoFuzzTest(const uint8_t* data, size_t size) FromJson(jsonObject, groupInfo); } -void RegisterDataChangeCbFuzzTest(const uint8_t* data, size_t size) -{ - (void)data; - (void)size; - - std::shared_ptr hiChainListener = std::make_shared(); - hiChainListener->deviceGroupManager_ = nullptr; - hiChainListener->RegisterDataChangeCb(); -} - -void RegisterCredentialCbFuzzTest(const uint8_t* data, size_t size) -{ - (void)data; - (void)size; - - std::shared_ptr hiChainListener = std::make_shared(); - hiChainListener->credManager_ = nullptr; - hiChainListener->RegisterCredentialCb(); -} - void OnHichainDeviceUnBoundFuzzTest(const uint8_t* data, size_t size) { if (data == nullptr || size == 0) { @@ -202,8 +182,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) /* Run your code on data */ OHOS::DistributedHardware::FromJsonFuzzTest(data, size); OHOS::DistributedHardware::FromJsonInfoFuzzTest(data, size); - OHOS::DistributedHardware::RegisterDataChangeCbFuzzTest(data, size); - OHOS::DistributedHardware::RegisterCredentialCbFuzzTest(data, size); OHOS::DistributedHardware::OnHichainDeviceUnBoundFuzzTest(data, size); OHOS::DistributedHardware::OnCredentialDeletedFuzzTest(data, size); OHOS::DistributedHardware::DeleteAllGroupFuzzTest(data, size); -- Gitee