From 68592b0cbae0cf404131602741be9a63dbd556d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Thu, 18 Jul 2024 16:31:17 +0800 Subject: [PATCH 1/6] =?UTF-8?q?=E5=B0=81=E8=A3=85=E5=87=BD=E6=95=B0?= =?UTF-8?q?=EF=BC=8C=E5=88=A0=E5=8E=BB=E5=85=B6=E4=BB=96=E9=9D=9E=E9=9C=80?= =?UTF-8?q?=E8=A6=81=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- common/utils/include/constants.h | 5 + .../src/distributed_hardware_fwk_kit.cpp | 13 ++- .../inner_kits/src/ipc/dhfwk_sa_manager.cpp | 7 ++ .../src/ipc/distributed_hardware_proxy.cpp | 13 ++- .../src/accessmanager/access_manager.cpp | 18 +-- .../src/componentloader/component_loader.cpp | 32 +++--- .../componentmanager/component_disable.cpp | 7 ++ .../src/componentmanager/component_enable.cpp | 7 ++ .../componentmanager/component_manager.cpp | 52 ++++++++- .../componentmanager/component_monitor.cpp | 8 ++ .../componentmanager/component_privacy.cpp | 18 ++- .../dh_data_sync_trigger_listener.cpp | 4 + .../componentmanager/dh_state_listener.cpp | 4 + .../src/distributed_hardware_manager.cpp | 6 + .../distributed_hardware_manager_factory.cpp | 13 +++ .../src/distributed_hardware_service.cpp | 9 ++ .../src/hidumphelper/enabled_comps_dump.cpp | 7 ++ .../src/ipc/publisher_listener_proxy.cpp | 4 +- .../local_hardware_manager.cpp | 3 +- .../plugin_listener_impl.cpp | 7 +- .../src/lowlatency/low_latency_listener.cpp | 7 +- .../src/publisher/publisher_item.cpp | 4 +- .../src/resourcemanager/capability_info.cpp | 11 ++ .../capability_info_manager.cpp | 57 ++++++++-- .../src/resourcemanager/capability_utils.cpp | 4 + .../src/resourcemanager/db_adapter.cpp | 33 +++++- .../local_capability_info_manager.cpp | 27 ++++- .../resourcemanager/meta_capability_info.cpp | 11 ++ .../src/resourcemanager/meta_info_manager.cpp | 42 +++++-- .../src/resourcemanager/version_info.cpp | 15 +++ .../resourcemanager/version_info_manager.cpp | 21 +++- .../src/transport/dh_comm_tool.cpp | 2 +- .../src/transport/dh_transport.cpp | 25 +++++ .../src/transport/dh_transport_obj.cpp | 17 +++ .../src/utils/dh_context.cpp | 42 +++++-- .../src/versionmanager/version_manager.cpp | 13 +++ .../src/mock_hardware_handler.cpp | 7 ++ utils/include/dh_utils_tool.h | 17 +++ utils/src/anonymous_string.cpp | 6 +- utils/src/dh_utils_tool.cpp | 86 +++++++++++++-- utils/src/histreamer_ability_parser.cpp | 104 +++++++++++++----- 41 files changed, 656 insertions(+), 132 deletions(-) diff --git a/common/utils/include/constants.h b/common/utils/include/constants.h index 5e2a6bea..52bd4b77 100644 --- a/common/utils/include/constants.h +++ b/common/utils/include/constants.h @@ -36,6 +36,11 @@ namespace DistributedHardware { constexpr int32_t MODE_ENABLE = 0; constexpr int32_t MODE_DISABLE = 1; constexpr uint32_t MAX_SWITCH_SIZE = 256; + constexpr uint32_t MAX_ROUND_SIZE = 1000; + constexpr uint32_t MAX_JSON_SIZE = 40 * 1024 * 1024; + constexpr uint32_t MAX_HASH_SIZE = 64; + constexpr uint32_t MAX_KEY_SIZE = 256; + const std::string LOW_LATENCY_KEY = "identity"; const std::u16string DHMS_STUB_INTERFACE_TOKEN = u"ohos.distributedhardware.accessToken"; const std::string APP_ID = "dtbhardware_manager_service"; diff --git a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp index 782e2dd5..b9ac608f 100644 --- a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp +++ b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp @@ -24,6 +24,7 @@ #include "distributed_hardware_log.h" #include "dh_utils_hisysevent.h" #include "idistributed_hardware.h" +#include "dh_utils_tool.h" namespace OHOS { namespace DistributedHardware { @@ -89,8 +90,7 @@ int32_t DistributedHardwareFwkKit::PublishMessage(const DHTopic topic, const std DHLOGE("Topic invalid, topic: %{public}" PRIu32, (uint32_t)topic); return ERR_DH_FWK_PARA_INVALID; } - if (message.empty() || message.size() > MAX_MESSAGE_LEN) { - DHLOGE("Message size is invalid!"); + if (MessageLengthInvalid(message)){ return ERR_DH_FWK_PARA_INVALID; } @@ -203,6 +203,9 @@ int32_t DistributedHardwareFwkKit::RegisterCtlCenterCallback(int32_t engineId, int32_t DistributedHardwareFwkKit::PauseDistributedHardware(DHType dhType, const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Pause distributed hardware dhType %{public}u, networkId %{public}s", (uint32_t)dhType, GetAnonyString(networkId).c_str()); @@ -217,6 +220,9 @@ int32_t DistributedHardwareFwkKit::PauseDistributedHardware(DHType dhType, const int32_t DistributedHardwareFwkKit::ResumeDistributedHardware(DHType dhType, const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Resume distributed hardware dhType %{public}u, networkId %{public}s", (uint32_t)dhType, GetAnonyString(networkId).c_str()); @@ -231,6 +237,9 @@ int32_t DistributedHardwareFwkKit::ResumeDistributedHardware(DHType dhType, cons int32_t DistributedHardwareFwkKit::StopDistributedHardware(DHType dhType, const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Stop distributed hardware dhType %{public}u, networkId %{public}s", (uint32_t)dhType, GetAnonyString(networkId).c_str()); diff --git a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp index ae595b0a..da5d299c 100644 --- a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp +++ b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp @@ -24,6 +24,7 @@ #include "distributed_hardware_log.h" #include "distributed_hardware_proxy.h" #include "distributed_hardware_errno.h" +#include "dh_utils_tool.h" namespace OHOS { namespace DistributedHardware { @@ -102,6 +103,9 @@ void DHFWKSAManager::RegisterSAStateCallback(DHFWKSAStateCb callback) void DHFWKSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { + if (IdLengthInvalid(deviceId)){ + return; + } (void)deviceId; if (systemAbilityId != DISTRIBUTED_HARDWARE_SA_ID) { DHLOGW("Receive SA Start, but sa id is not DHFWK, id: %{public}" PRId32, systemAbilityId); @@ -123,6 +127,9 @@ void DHFWKSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbi void DHFWKSAManager::SystemAbilityListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { + if (IdLengthInvalid(deviceId)){ + return; + } (void)deviceId; if (systemAbilityId != DISTRIBUTED_HARDWARE_SA_ID) { DHLOGW("Receive SA Stop, but sa id is not DHFWK, id: %{public}" PRId32, systemAbilityId); diff --git a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp index a1abe8eb..aeb06219 100644 --- a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp +++ b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp @@ -24,6 +24,7 @@ #include "dhardware_ipc_interface_code.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" +#include "dh_utils_tool.h" #include "parcel.h" namespace OHOS { @@ -144,8 +145,7 @@ int32_t DistributedHardwareProxy::PublishMessage(const DHTopic topic, const std: DHLOGE("Topic is invalid!"); return ERR_DH_FWK_PARA_INVALID; } - if (msg.empty() || msg.size() > MAX_MESSAGE_LEN) { - DHLOGE("Msg is invalid"); + if (MessageLengthInvalid(msg)) { return ERR_DH_FWK_SERVICE_MSG_INVALID; } @@ -416,6 +416,9 @@ int32_t DistributedHardwareProxy::NotifySourceRemoteSinkStarted(std::string &dev int32_t DistributedHardwareProxy::PauseDistributedHardware(DHType dhType, const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return ERR_DH_FWK_PARA_INVALID; + } sptr remote = Remote(); if (remote == nullptr) { DHLOGE("remote service is null"); @@ -451,6 +454,9 @@ int32_t DistributedHardwareProxy::PauseDistributedHardware(DHType dhType, const int32_t DistributedHardwareProxy::ResumeDistributedHardware(DHType dhType, const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return ERR_DH_FWK_PARA_INVALID; + } sptr remote = Remote(); if (remote == nullptr) { DHLOGE("remote service is null"); @@ -486,6 +492,9 @@ int32_t DistributedHardwareProxy::ResumeDistributedHardware(DHType dhType, const int32_t DistributedHardwareProxy::StopDistributedHardware(DHType dhType, const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return ERR_DH_FWK_PARA_INVALID; + } sptr remote = Remote(); if (remote == nullptr) { DHLOGE("remote service is null"); diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index a2f8df6f..9bb8b2c9 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -130,14 +130,9 @@ void AccessManager::OnDeviceOffline(const DmDeviceInfo &deviceInfo) deviceInfo.deviceTypeId); auto networkId = std::string(deviceInfo.networkId); - if (networkId.size() == 0 || networkId.size() > MAX_ID_LEN) { - DHLOGE("NetworkId is invalid!"); - return; - } std::string uuid = DHContext::GetInstance().GetUUIDByNetworkId(networkId); std::string udid = DHContext::GetInstance().GetUDIDByNetworkId(networkId); - if (uuid.empty() || uuid.size() > MAX_ID_LEN || udid.empty() || udid.size() > MAX_ID_LEN) { - DHLOGE("uuid or udid is invalid!"); + if (IdLengthInvalid(networkId,uuid,udid)){ return; } @@ -155,18 +150,9 @@ void AccessManager::OnDeviceReady(const DmDeviceInfo &deviceInfo) deviceInfo.deviceTypeId); auto networkId = std::string(deviceInfo.networkId); - if (networkId.size() == 0 || networkId.size() > MAX_ID_LEN) { - DHLOGE("NetworkId is invalid!"); - return; - } auto uuid = GetUUIDByDm(networkId); - if (uuid.size() == 0 || uuid.size() > MAX_ID_LEN) { - DHLOGE("Uuid is invalid!"); - return; - } auto udid = GetUDIDByDm(networkId); - if (udid.size() == 0 || udid.size() > MAX_ID_LEN) { - DHLOGE("Udid is invalid!"); + if (IdLengthInvalid(networkId,uuid,udid)){ return; } auto ret = diff --git a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp index 9f65636e..c6d68fb7 100644 --- a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp +++ b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp @@ -115,22 +115,22 @@ std::vector ComponentLoader::GetAllCompTypes() int32_t ParseComponent(const cJSON *json, CompConfig &cfg) { if (!IsString(json, COMP_NAME)) { - DHLOGE("COMP_NAME is invalid"); + DHLOGE("COMP_NAME is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.name = cJSON_GetObjectItem(json, COMP_NAME.c_str())->valuestring; if (!IsString(json, COMP_TYPE)) { - DHLOGE("COMP_TYPE is invalid"); + DHLOGE("COMP_TYPE is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.type = g_mapDhTypeName[cJSON_GetObjectItem(json, COMP_TYPE.c_str())->valuestring]; if (!IsString(json, COMP_HANDLER_LOC)) { - DHLOGE("COMP_HANDLER_LOC is invalid"); + DHLOGE("COMP_HANDLER_LOC is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compHandlerLoc = cJSON_GetObjectItem(json, COMP_HANDLER_LOC.c_str())->valuestring; if (!IsString(json, COMP_HANDLER_VERSION)) { - DHLOGE("COMP_HANDLER_VERSION is invalid"); + DHLOGE("COMP_HANDLER_VERSION is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compHandlerVersion = cJSON_GetObjectItem(json, COMP_HANDLER_VERSION.c_str())->valuestring; @@ -140,17 +140,17 @@ int32_t ParseComponent(const cJSON *json, CompConfig &cfg) int32_t ParseSource(const cJSON *json, CompConfig &cfg) { if (!IsString(json, COMP_SOURCE_LOC)) { - DHLOGE("COMP_SOURCE_LOC is invalid"); + DHLOGE("COMP_SOURCE_LOC is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compSourceLoc = cJSON_GetObjectItem(json, COMP_SOURCE_LOC.c_str())->valuestring; if (!IsString(json, COMP_SOURCE_VERSION)) { - DHLOGE("COMP_SOURCE_VERSION is invalid"); + DHLOGE("COMP_SOURCE_VERSION is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compSourceVersion = cJSON_GetObjectItem(json, COMP_SOURCE_VERSION.c_str())->valuestring; if (!IsInt32(json, COMP_SOURCE_SA_ID)) { - DHLOGE("COMP_SOURCE_SA_ID is invalid"); + DHLOGE("COMP_SOURCE_SA_ID is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compSourceSaId = static_cast(cJSON_GetObjectItem(json, COMP_SOURCE_SA_ID.c_str())->valuedouble); @@ -160,17 +160,17 @@ int32_t ParseSource(const cJSON *json, CompConfig &cfg) int32_t ParseSink(const cJSON *json, CompConfig &cfg) { if (!IsString(json, COMP_SINK_LOC)) { - DHLOGE("COMP_SINK_LOC is invalid"); + DHLOGE("COMP_SINK_LOC is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compSinkLoc = cJSON_GetObjectItem(json, COMP_SINK_LOC.c_str())->valuestring; if (!IsString(json, COMP_SINK_VERSION)) { - DHLOGE("COMP_SINK_VERSION is invalid"); + DHLOGE("COMP_SINK_VERSION is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compSinkVersion = cJSON_GetObjectItem(json, COMP_SINK_VERSION.c_str())->valuestring; if (!IsInt32(json, COMP_SINK_SA_ID)) { - DHLOGE("COMP_SINK_SA_ID is invalid"); + DHLOGE("COMP_SINK_SA_ID is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cfg.compSinkSaId = static_cast(cJSON_GetObjectItem(json, COMP_SINK_SA_ID.c_str())->valuedouble); @@ -180,7 +180,7 @@ int32_t ParseSink(const cJSON *json, CompConfig &cfg) int32_t ParseResourceDesc(const cJSON *json, CompConfig &cfg) { if (!IsArray(json, COMP_RESOURCE_DESC)) { - DHLOGE("COMP_RESOURCE_DESC is invalid"); + DHLOGE("COMP_RESOURCE_DESC is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } cJSON *resourceDescArray = cJSON_GetObjectItem(json, COMP_RESOURCE_DESC.c_str()); @@ -188,7 +188,7 @@ int32_t ParseResourceDesc(const cJSON *json, CompConfig &cfg) cJSON_ArrayForEach(element, resourceDescArray) { ResourceDesc desc; if (!IsString(element, COMP_SUBTYPE)) { - DHLOGE("COMP_SUBTYPE is invalid"); + DHLOGE("COMP_SUBTYPE is invalid!"); return ERR_DH_FWK_JSON_PARSE_FAILED; } desc.subtype = cJSON_GetObjectItem(element, COMP_SUBTYPE.c_str())->valuestring; @@ -252,6 +252,9 @@ bool ComponentLoader::CheckComponentEnable(const CompConfig &config) int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std::map &dhtypeMap) { + if (JsonLengthInvalid(jsonStr)){ + return ERR_DH_FWK_PARA_INVALID; + } cJSON *root = cJSON_Parse(jsonStr.c_str()); if (root == NULL) { DHLOGE("jsonStr parse failed"); @@ -336,7 +339,7 @@ void ComponentLoader::ParseResourceDescFromJson(cJSON *resourceDescs, CompConfig } ResourceDesc resource; if (!IsString(resourceDesc, COMP_SUBTYPE)) { - DHLOGE("COMP_SUBTYPE is invalid"); + DHLOGE("COMP_SUBTYPE is invalid!"); return; } resource.subtype = cJSON_GetObjectItem(resourceDesc, COMP_SUBTYPE.c_str())->valuestring; @@ -514,8 +517,7 @@ int32_t ComponentLoader::ParseConfig() } std::string componentProfilePath(path); std::string jsonStr = Readfile(componentProfilePath); - if (jsonStr.length() == 0 || jsonStr.size() > MAX_MESSAGE_LEN) { - DHLOGE("ConfigJson size is invalid!"); + if (MessageLengthInvalid(jsonStr)){ return ERR_DH_FWK_LOADER_CONFIG_JSON_INVALID; } ret = GetCompPathAndVersion(jsonStr, dhtypeMap); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_disable.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_disable.cpp index c70b14cd..2732452c 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_disable.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_disable.cpp @@ -18,6 +18,7 @@ #include "anonymous_string.h" #include "constants.h" #include "dh_utils_hisysevent.h" +#include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" @@ -33,6 +34,9 @@ ComponentDisable::~ComponentDisable() {} int32_t ComponentDisable::Disable(const std::string &networkId, const std::string &dhId, IDistributedHardwareSource *handler) { + if (IdLengthInvalid(networkId,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGD("networkId = %{public}s dhId = %{public}s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); if (handler == nullptr) { @@ -68,6 +72,9 @@ int32_t ComponentDisable::Disable(const std::string &networkId, const std::strin int32_t ComponentDisable::OnUnregisterResult(const std::string &networkId, const std::string &dhId, int32_t status, const std::string &data) { + if (IdLengthInvalid(networkId,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } if (status == DH_FWK_SUCCESS) { DHLOGI("disable success, networkId = %{public}s, dhId = %{public}s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_enable.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_enable.cpp index d0f757b0..1bd66eb8 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_enable.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_enable.cpp @@ -18,6 +18,7 @@ #include "anonymous_string.h" #include "constants.h" #include "dh_utils_hisysevent.h" +#include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" @@ -33,6 +34,9 @@ ComponentEnable::~ComponentEnable() {} int32_t ComponentEnable::Enable(const std::string &networkId, const std::string &dhId, const EnableParam ¶m, IDistributedHardwareSource *handler) { + if (IdLengthInvalid(networkId,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGD("networkId = %{public}s dhId = %{public}s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); if (handler == nullptr) { @@ -68,6 +72,9 @@ int32_t ComponentEnable::Enable(const std::string &networkId, const std::string int32_t ComponentEnable::OnRegisterResult(const std::string &networkId, const std::string &dhId, int32_t status, const std::string &data) { + if (IdLengthInvalid(networkId,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } if (status == DH_FWK_SUCCESS) { DHLOGI("enable success, networkId = %{public}s, dhId = %{public}s.", GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str()); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 525268eb..1c226221 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -516,6 +516,9 @@ bool ComponentManager::InitCompSink() int32_t ComponentManager::Enable(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType) { + if (IdLengthInvalid(networkId,uuid,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("start."); auto find = compSource_.find(dhType); if (find == compSource_.end()) { @@ -571,6 +574,9 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string int32_t ComponentManager::RetryGetEnableParam(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType, EnableParam ¶m) { + if (IdLengthInvalid(networkId,uuid,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } for (int32_t retryCount = 0; retryCount < ENABLE_RETRY_MAX_TIMES; retryCount++) { if (!DHContext::GetInstance().IsDeviceOnline(uuid)) { DHLOGE("device is already offline, no need try GetEnableParam, uuid = %{public}s", @@ -590,12 +596,15 @@ int32_t ComponentManager::RetryGetEnableParam(const std::string &networkId, cons int32_t ComponentManager::Disable(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType) { + if (IdLengthInvalid(networkId,uuid,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } auto find = compSource_.find(dhType); if (find == compSource_.end()) { DHLOGE("can not find handler for dhId = %{public}s.", GetAnonyString(dhId).c_str()); return ERR_DH_FWK_PARA_INVALID; } - + auto compDisable = std::make_shared(); auto result = compDisable->Disable(networkId, dhId, find->second); if (result != DH_FWK_SUCCESS) { @@ -636,6 +645,9 @@ DHType ComponentManager::GetDHType(const std::string &uuid, const std::string &d int32_t ComponentManager::GetEnableCapParam(const std::string &networkId, const std::string &uuid, DHType dhType, EnableParam ¶m, std::shared_ptr &capability) { + if (IdLengthInvalid(networkId,uuid)){ + return ERR_DH_FWK_PARA_INVALID; + } DeviceInfo sourceDeviceInfo = GetLocalDeviceInfo(); std::vector> sourceCapInfos; std::string sourceDHId; @@ -682,6 +694,9 @@ int32_t ComponentManager::GetEnableCapParam(const std::string &networkId, const int32_t ComponentManager::GetEnableMetaParam(const std::string &networkId, const std::string &uuid, DHType dhType, EnableParam ¶m, std::shared_ptr &metaCapPtr) { + if (IdLengthInvalid(networkId,uuid)){ + return ERR_DH_FWK_PARA_INVALID; + } DeviceInfo sourceDeviceInfo = GetLocalDeviceInfo(); std::vector> sourceMetaInfos; std::string sourceDHId; @@ -714,6 +729,9 @@ int32_t ComponentManager::GetEnableMetaParam(const std::string &networkId, const int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string &dhId, std::shared_ptr &capability) { + if (IdLengthInvalid(uuid,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } std::string deviceId = GetDeviceIdByUUID(uuid); auto ret = CapabilityInfoManager::GetInstance()->GetCapability(deviceId, dhId, capability); if ((ret == DH_FWK_SUCCESS) && (capability != nullptr)) { @@ -735,6 +753,9 @@ int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string int32_t ComponentManager::GetMetaParam(const std::string &uuid, const std::string &dhId, std::shared_ptr &metaCapPtr) { + if (IdLengthInvalid(uuid,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(DHContext::GetInstance().GetUdidHashIdByUUID(uuid), dhId, metaCapPtr); if ((ret == DH_FWK_SUCCESS) && (metaCapPtr != nullptr)) { @@ -748,6 +769,9 @@ int32_t ComponentManager::GetMetaParam(const std::string &uuid, const std::strin int32_t ComponentManager::GetEnableParam(const std::string &networkId, const std::string &uuid, const std::string &dhId, DHType dhType, EnableParam ¶m) { + if (IdLengthInvalid(networkId,uuid,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("GetEnableParam start, networkId= %{public}s, uuid = %{public}s, dhId = %{public}s, dhType = %{public}#X,", GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(dhId).c_str(), dhType); std::shared_ptr capability = nullptr; @@ -774,6 +798,9 @@ int32_t ComponentManager::GetEnableParam(const std::string &networkId, const std int32_t ComponentManager::GetVersionFromVerMgr(const std::string &uuid, const DHType dhType, std::string &version, bool isSink) { + if (IdLengthInvalid(uuid)){ + return ERR_DH_FWK_PARA_INVALID; + } CompVersion compversion; int32_t ret = VersionManager::GetInstance().GetCompVersion(uuid, dhType, compversion); if (ret != DH_FWK_SUCCESS) { @@ -791,6 +818,9 @@ int32_t ComponentManager::GetVersionFromVerMgr(const std::string &uuid, const DH int32_t ComponentManager::GetVersionFromVerInfoMgr(const std::string &uuid, const DHType dhType, std::string &version, bool isSink) { + if (IdLengthInvalid(uuid)){ + return ERR_DH_FWK_PARA_INVALID; + } VersionInfo versionInfo; int32_t ret = VersionInfoManager::GetInstance()->GetVersionInfoByDeviceId(GetDeviceIdByUUID(uuid), versionInfo); if (ret != DH_FWK_SUCCESS) { @@ -813,6 +843,9 @@ int32_t ComponentManager::GetVersionFromVerInfoMgr(const std::string &uuid, cons int32_t ComponentManager::GetVersion(const std::string &uuid, DHType dhType, std::string &version, bool isSink) { + if (IdLengthInvalid(uuid)){ + return ERR_DH_FWK_PARA_INVALID; + } int32_t ret = GetVersionFromVerMgr(uuid, dhType, version, isSink); if ((ret == DH_FWK_SUCCESS) && (!version.empty())) { return DH_FWK_SUCCESS; @@ -828,6 +861,9 @@ int32_t ComponentManager::GetVersion(const std::string &uuid, DHType dhType, std void ComponentManager::UpdateVersionCache(const std::string &uuid, const VersionInfo &versionInfo) { + if (IdLengthInvalid(uuid)){ + return; + } DHVersion dhVersion; dhVersion.uuid = uuid; dhVersion.dhVersion = versionInfo.dhVersion; @@ -914,6 +950,9 @@ std::map ComponentManager::GetDHSinkInstance( bool ComponentManager::IsIdenticalAccount(const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return false; + } DmAuthForm authForm = DmAuthForm::INVALID_TYPE; std::vector deviceList; DeviceManager::GetInstance().GetTrustedDeviceList(DH_FWK_PKG_NAME, "", deviceList); @@ -935,6 +974,9 @@ bool ComponentManager::IsIdenticalAccount(const std::string &networkId) void ComponentManager::UpdateBusinessState(const std::string &networkId, const std::string &dhId, BusinessState state) { + if (IdLengthInvalid(networkId,dhId)){ + return; + } DHLOGI("UpdateBusinessState, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str(), (uint32_t)state); { @@ -956,6 +998,9 @@ void ComponentManager::UpdateBusinessState(const std::string &networkId, const s BusinessState ComponentManager::QueryBusinessState(const std::string &uuid, const std::string &dhId) { + if (IdLengthInvalid(uuid,dhId)){ + return BusinessState::UNKNOWN; + } std::lock_guard lock(bizStateMtx_); std::pair key = {uuid, dhId}; if (dhBizStates_.find(key) == dhBizStates_.end()) { @@ -967,8 +1012,7 @@ BusinessState ComponentManager::QueryBusinessState(const std::string &uuid, cons void ComponentManager::TriggerFullCapsSync(const std::string &networkId) { - if (networkId.empty()) { - DHLOGE("Remote networkid is null"); + if (IdLengthInvalid(networkId)){ return; } dhCommToolPtr_->TriggerReqFullDHCaps(networkId); @@ -1007,7 +1051,7 @@ void ComponentManager::ComponentManagerEventHandler::ProcessEvent( // do muanul sync with remote auto sharedObjPtr = event->GetSharedObject(); if (sharedObjPtr == nullptr) { - DHLOGE("The data sync param invalid"); + DHLOGE("The data sync param invalid!"); break; } std::string networkId = *sharedObjPtr; diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp index fdcd7026..1220cc26 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp @@ -25,8 +25,10 @@ #include "component_loader.h" #include "component_manager.h" #include "device_type.h" +#include "constants.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" +#include "dh_utils_tool.h" namespace OHOS { namespace DistributedHardware { @@ -47,11 +49,17 @@ ComponentMonitor::~ComponentMonitor() void ComponentMonitor::CompSystemAbilityListener::OnAddSystemAbility(int32_t saId, const std::string &deviceId) { + if (IdLengthInvalid(deviceId)){ + return; + } DHLOGI("OnAddSystemAbility, saId: %{public}d, deviceId: %{public}s", saId, GetAnonyString(deviceId).c_str()); } void ComponentMonitor::CompSystemAbilityListener::OnRemoveSystemAbility(int32_t saId, const std::string &deviceId) { + if (IdLengthInvalid(deviceId)){ + return; + } DHLOGI("OnRemoveSystemAbility, saId: %{public}d, deviceId: %{public}s", saId, GetAnonyString(deviceId).c_str()); DHType dhType = ComponentLoader::GetInstance().GetDHTypeBySrcSaId(saId); if (dhType == DHType::UNKNOWN) { diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp index 6e836376..51c88716 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp @@ -47,6 +47,9 @@ ComponentPrivacy::~ComponentPrivacy() int32_t ComponentPrivacy::OnPrivaceResourceMessage(const ResourceEventType &type, const std::string &subtype, const std::string &networkId, bool &isSensitive, bool &isSameAccout) { + if (IdLengthInvalid(networkId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("OnPrivaceResourceMessage start."); int32_t ret = DH_FWK_SUCCESS; if (type == ResourceEventType::EVENT_TYPE_QUERY_RESOURCE) { @@ -61,6 +64,9 @@ int32_t ComponentPrivacy::OnPrivaceResourceMessage(const ResourceEventType &type void ComponentPrivacy::HandlePullUpPage(const std::string &subtype, const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return; + } cJSON *jsonArrayMsg = cJSON_CreateArray(); if (jsonArrayMsg == NULL) { DHLOGE("Failed to create cJSON arrary."); @@ -119,6 +125,9 @@ void ComponentPrivacy::HandleClosePage(const std::string &subtype) int32_t ComponentPrivacy::OnResourceInfoCallback(const std::string &subtype, const std::string &networkId, bool &isSensitive, bool &isSameAccout) { + if (IdLengthInvalid(networkId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("OnResourceInfoCallback start."); std::map resourceDesc = ComponentLoader::GetInstance().GetCompResourceDesc(); if (resourceDesc.find(subtype) == resourceDesc.end()) { @@ -149,6 +158,9 @@ int32_t ComponentPrivacy::OnResourceInfoCallback(const std::string &subtype, con int32_t ComponentPrivacy::StartPrivacePage(const std::string &subtype, const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("StartPrivacePage start."); DmDeviceInfo deviceInfo; DeviceManager::GetInstance().GetDeviceInfo(DH_FWK_PKG_NAME, networkId, deviceInfo); @@ -285,12 +297,12 @@ void ComponentPrivacy::ComponentEventHandler::ProcessStartPage(const AppExecFwk: std::shared_ptr dataMsg = event->GetSharedObject(); cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0); if (!IsString(innerMsg, PRIVACY_SUBTYPE)) { - DHLOGE("PRIVACY_SUBTYPE is invalid"); + DHLOGE("PRIVACY_SUBTYPE is invalid!"); return; } std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring; if (!IsString(innerMsg, PRIVACY_NETWORKID)) { - DHLOGE("PRIVACY_NETWORKID is invalid"); + DHLOGE("PRIVACY_NETWORKID is invalid!"); return; } std::string networkId = cJSON_GetObjectItem(innerMsg, PRIVACY_NETWORKID.c_str())->valuestring; @@ -303,7 +315,7 @@ void ComponentPrivacy::ComponentEventHandler::ProcessStopPage(const AppExecFwk:: std::shared_ptr dataMsg = event->GetSharedObject(); cJSON *innerMsg = cJSON_GetArrayItem(dataMsg.get(), 0); if (!IsString(innerMsg, PRIVACY_SUBTYPE)) { - DHLOGE("PRIVACY_SUBTYPE is invalid"); + DHLOGE("PRIVACY_SUBTYPE is invalid!"); return; } std::string subtype = cJSON_GetObjectItem(innerMsg, PRIVACY_SUBTYPE.c_str())->valuestring; diff --git a/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp b/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp index 74ebc3ed..11daa72a 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp @@ -21,6 +21,7 @@ #include "component_manager.h" #include "distributed_hardware_log.h" #include "event_handler.h" +#include "dh_utils_tool.h" class ComponentManager; namespace OHOS { @@ -39,6 +40,9 @@ DHDataSyncTriggerListener::~DHDataSyncTriggerListener() void DHDataSyncTriggerListener::OnDataSyncTrigger(const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return; + } DHLOGI("Receive data sync trigger, networkId: %{public}s", GetAnonyString(networkId).c_str()); if (networkId.empty()) { DHLOGE("OnDataSyncTrigger networkId is empty"); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp b/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp index 9ce4d817..cff438a4 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp @@ -20,6 +20,7 @@ #include "anonymous_string.h" #include "component_manager.h" #include "distributed_hardware_log.h" +#include "dh_utils_tool.h" class ComponentManager; namespace OHOS { @@ -38,6 +39,9 @@ DHStateListener::~DHStateListener() void DHStateListener::OnStateChanged(const std::string &networkId, const std::string &dhId, const BusinessState state) { + if (IdLengthInvalid(networkId)){ + return; + } DHLOGI("Receive business state change, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, GetAnonyString(networkId).c_str(), GetAnonyString(dhId).c_str(), (uint32_t)state); ComponentManager::GetInstance().UpdateBusinessState(networkId, dhId, state); diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp index 2df70d68..c3db4a41 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp @@ -97,6 +97,9 @@ int32_t DistributedHardwareManager::Release() int32_t DistributedHardwareManager::SendOnLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType) { + if (IdLengthInvalid(networkId,uuid,udid)){ + return ERR_DH_FWK_PARA_INVALID; + } (void)deviceType; DHLOGI("SendOnLineEvent networkId = %{public}s, uuid = %{public}s, udid = %{public}s", GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(udid).c_str()); @@ -116,6 +119,9 @@ int32_t DistributedHardwareManager::SendOnLineEvent(const std::string &networkId int32_t DistributedHardwareManager::SendOffLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType) { + if (IdLengthInvalid(networkId,uuid,udid)){ + return ERR_DH_FWK_PARA_INVALID; + } (void)deviceType; DHLOGI("SendOffLineEvent networkId = %{public}s, uuid = %{public}s, udid = %{public}s", GetAnonyString(networkId).c_str(), GetAnonyString(uuid).c_str(), GetAnonyString(udid).c_str()); diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 6133e6f7..6ed0f39f 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -148,6 +148,9 @@ bool DistributedHardwareManagerFactory::IsInit() int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType) { + if (IdLengthInvalid(networkId,uuid,udid)){ + return ERR_DH_FWK_PARA_INVALID; + } int32_t ret = pthread_setname_np(pthread_self(), SEND_ONLINE); if (ret != DH_FWK_SUCCESS) { DHLOGE("SendOnLineEvent setname failed."); @@ -176,6 +179,9 @@ int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &ne int32_t DistributedHardwareManagerFactory::SendOffLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType) { + if (IdLengthInvalid(networkId,uuid,udid)){ + return ERR_DH_FWK_PARA_INVALID; + } if (!isInit && !Init()) { DHLOGE("distributedHardwareMgr is null"); return ERR_DH_FWK_HARDWARE_MANAGER_INIT_FAILED; @@ -191,6 +197,13 @@ int32_t DistributedHardwareManagerFactory::SendOffLineEvent(const std::string &n if (offlineResult != DH_FWK_SUCCESS) { DHLOGE("offline failed, errCode = %{public}d", offlineResult); } + + DHContext::GetInstance().RemoveOnlineDeviceByUUID(uuid); + if (DistributedHardwareManager::GetInstance().GetOnLineCount() == 0 && + DHContext::GetInstance().GetIsomerismConnectCount() == 0) { + DHLOGI("all devices are offline, start to free the resource"); + UnInit(); + } return DH_FWK_SUCCESS; } diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index 3f2bf503..732746f9 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -306,6 +306,9 @@ int DistributedHardwareService::Dump(int32_t fd, const std::vector sinkMap = ComponentManager::GetInstance().GetDHSinkInstance(); if (sinkMap.find(dhType) == sinkMap.end()) { DHLOGE("PauseDistributedHardware for DHType: %{public}u not init sink handler", (uint32_t)dhType); @@ -321,6 +324,9 @@ int32_t DistributedHardwareService::PauseDistributedHardware(DHType dhType, cons int32_t DistributedHardwareService::ResumeDistributedHardware(DHType dhType, const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return ERR_DH_FWK_PARA_INVALID; + } std::map sinkMap = ComponentManager::GetInstance().GetDHSinkInstance(); if (sinkMap.find(dhType) == sinkMap.end()) { DHLOGE("ResumeDistributedHardware for DHType: %{public}u not init sink handler", (uint32_t)dhType); @@ -336,6 +342,9 @@ int32_t DistributedHardwareService::ResumeDistributedHardware(DHType dhType, con int32_t DistributedHardwareService::StopDistributedHardware(DHType dhType, const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return ERR_DH_FWK_PARA_INVALID; + } std::map sinkMap = ComponentManager::GetInstance().GetDHSinkInstance(); if (sinkMap.find(dhType) == sinkMap.end()) { DHLOGE("StopDistributedHardware for DHType: %{public}u not init sink handler", (uint32_t)dhType); diff --git a/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp b/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp index abfd99cb..47f14c25 100644 --- a/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp +++ b/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp @@ -14,6 +14,7 @@ */ #include "enabled_comps_dump.h" +#include "dh_utils_tool.h" namespace OHOS { namespace DistributedHardware { @@ -21,6 +22,9 @@ IMPLEMENT_SINGLE_INSTANCE(EnabledCompsDump); void EnabledCompsDump::DumpEnabledComp(const std::string &networkId, const DHType dhType, const std::string &dhId) { + if (IdLengthInvalid(networkId,dhId)){ + return; + } HidumpCompInfo info(networkId, dhType, dhId); std::lock_guard lock(compInfosMutex_); @@ -29,6 +33,9 @@ void EnabledCompsDump::DumpEnabledComp(const std::string &networkId, const DHTyp void EnabledCompsDump::DumpDisabledComp(const std::string &networkId, const DHType dhType, const std::string &dhId) { + if (IdLengthInvalid(networkId,dhId)){ + return; + } HidumpCompInfo info(networkId, dhType, dhId); std::lock_guard lock(compInfosMutex_); diff --git a/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp b/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp index 11fdf70a..ca44ea78 100644 --- a/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp +++ b/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp @@ -16,6 +16,7 @@ #include "constants.h" #include "distributed_hardware_log.h" #include "publisher_listener_proxy.h" +#include "dh_utils_tool.h" namespace OHOS { namespace DistributedHardware { @@ -39,8 +40,7 @@ void PublisherListenerProxy::OnMessage(const DHTopic topic, const std::string& m DHLOGE("Topic is invalid!"); return; } - if (message.size() == 0 || message.size() > MAX_MESSAGE_LEN) { - DHLOGE("Message is invalid"); + if (MessageLengthInvalid(message)) { return; } diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp index 1146c1d9..6ea9c0a8 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp @@ -196,8 +196,7 @@ void LocalHardwareManager::CheckNonExistCapabilityInfo(const std::vector void LocalHardwareManager::GetLocalCapabilityMapByPrefix(const DHType dhType, CapabilityInfoMap &capabilityInfoMap) { std::string localDeviceId = DHContext::GetInstance().GetDeviceInfo().deviceId; - if (localDeviceId.size() == 0 || localDeviceId.size() > MAX_ID_LEN) { - DHLOGE("LocalDeviceId is invalid"); + if (IdLengthInvalid(localDeviceId)){ return; } if (DHTypePrefixMap.find(dhType) == DHTypePrefixMap.end()) { diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp index 103b836c..cd2930e9 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp @@ -22,6 +22,7 @@ #include "dh_context.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" +#include "dh_utils_tool.h" #include "publisher.h" namespace OHOS { @@ -31,8 +32,7 @@ namespace DistributedHardware { void PluginListenerImpl::PluginHardware(const std::string &dhId, const std::string &attrs, const std::string &subtype) { - if (dhId.size() == 0 || dhId.size() > MAX_ID_LEN || attrs.size() == 0 || attrs.size() > MAX_MESSAGE_LEN) { - DHLOGE("Param is invalid!"); + if (IdLengthInvalid(dhId) || MessageLengthInvalid(attrs)) { return; } DHLOGI("plugin start, dhId: %{public}s", GetAnonyString(dhId).c_str()); @@ -55,8 +55,7 @@ void PluginListenerImpl::PluginHardware(const std::string &dhId, const std::stri void PluginListenerImpl::UnPluginHardware(const std::string &dhId) { - if (dhId.size() == 0 || dhId.size() > MAX_ID_LEN) { - DHLOGE("DhId is invalid!"); + if (IdLengthInvalid(dhId)){ return; } DHLOGI("unplugin start, dhId: %{public}s", GetAnonyString(dhId).c_str()); diff --git a/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp b/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp index 3cd6c701..6119ab72 100644 --- a/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp +++ b/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp @@ -45,8 +45,7 @@ void LowLatencyListener::OnMessage(const DHTopic topic, const std::string& messa DHLOGE("Topic is invalid, topic: %{public}" PRIu32, (uint32_t)topic); return; } - if (message.size() == 0 || message.size() > MAX_MESSAGE_LEN) { - DHLOGE("Message is invalid"); + if (MessageLengthInvalid(message)){ return; } cJSON *jsonObj = cJSON_Parse(message.c_str()); @@ -55,12 +54,12 @@ void LowLatencyListener::OnMessage(const DHTopic topic, const std::string& messa return; } if (!IsUInt32(jsonObj, DH_TYPE)) { - DHLOGE("The DH_TYPE key is invalid"); + DHLOGE("The DH_TYPE key is invalid!"); cJSON_Delete(jsonObj); return; } if (!IsBool(jsonObj, LOW_LATENCY_ENABLE)) { - DHLOGE("The LOW_LATENCY_ENABLE key is invalid"); + DHLOGE("The LOW_LATENCY_ENABLE key is invalid!"); cJSON_Delete(jsonObj); return; } diff --git a/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp b/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp index fd757809..8218697d 100644 --- a/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp +++ b/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp @@ -16,6 +16,7 @@ #include "constants.h" #include "publisher_item.h" #include "distributed_hardware_log.h" +#include "dh_utils_tool.h" namespace OHOS { namespace DistributedHardware { @@ -64,8 +65,7 @@ void PublisherItem::RemoveListener(const sptr &listener) void PublisherItem::PublishMessage(const std::string &message) { - if (message.size() == 0 || message.size() > MAX_MESSAGE_LEN) { - DHLOGE("Message is invalid"); + if (MessageLengthInvalid(message)){ return; } std::lock_guard lock(mutex_); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info.cpp index 7f65f5f8..bd2f3067 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info.cpp @@ -120,6 +120,9 @@ std::string CapabilityInfo::GetAnonymousKey() const int32_t CapabilityInfo::FromJsonString(const std::string &jsonStr) { + if (JsonLengthInvalid(jsonStr)){ + return ERR_DH_FWK_PARA_INVALID; + } cJSON *jsonObj = cJSON_Parse(jsonStr.c_str()); if (jsonObj == NULL) { DHLOGE("jsonStr parse failed"); @@ -185,6 +188,10 @@ bool CapabilityInfo::Compare(const CapabilityInfo& capInfo) void ToJson(cJSON *jsonObject, const CapabilityInfo &capability) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } cJSON_AddStringToObject(jsonObject, DH_ID.c_str(), capability.GetDHId().c_str()); cJSON_AddStringToObject(jsonObject, DEV_ID.c_str(), capability.GetDeviceId().c_str()); cJSON_AddStringToObject(jsonObject, DEV_NAME.c_str(), capability.GetDeviceName().c_str()); @@ -196,6 +203,10 @@ void ToJson(cJSON *jsonObject, const CapabilityInfo &capability) void FromJson(const cJSON *jsonObject, CapabilityInfo &capability) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, DH_ID)) { DHLOGE("DH_ID is invalid!"); return; diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp index 7c4eed6f..3d3660b5 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp @@ -119,6 +119,9 @@ int32_t CapabilityInfoManager::UnInit() int32_t CapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &deviceId) { + if (IdLengthInvalid(deviceId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Sync DeviceInfo from DB, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -130,8 +133,7 @@ int32_t CapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &deviceId) DHLOGE("Query data from DB by deviceId failed, id: %{public}s", GetAnonyString(deviceId).c_str()); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (dataVector.size() == 0 || dataVector.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("DataVector size is invalid!"); + if (RecordSizeInvalid(dataVector)){ return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -158,8 +160,7 @@ int32_t CapabilityInfoManager::SyncRemoteCapabilityInfos() DHLOGE("Query all data from DB failed"); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (dataVector.size() == 0 || dataVector.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("DataVector size is invalid!"); + if (RecordSizeInvalid(dataVector)){ return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -185,8 +186,7 @@ int32_t CapabilityInfoManager::SyncRemoteCapabilityInfos() int32_t CapabilityInfoManager::AddCapability(const std::vector> &resInfos) { - if (resInfos.size() == 0 || resInfos.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("ResInfos size is invalid!"); + if (RecordSizeInvalid(resInfos)){ return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -226,6 +226,9 @@ int32_t CapabilityInfoManager::AddCapability(const std::vector> &resInfos) { + if (RecordSizeInvalid(resInfos)){ + return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); for (auto &resInfo : resInfos) { if (resInfo == nullptr) { @@ -240,8 +243,7 @@ int32_t CapabilityInfoManager::AddCapabilityInMem(const std::vector MAX_ID_LEN) { - DHLOGE("DeviceId is invalid!"); + if (IdLengthInvalid(deviceId)){ return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Remove capability device info, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); @@ -269,6 +271,9 @@ int32_t CapabilityInfoManager::RemoveCapabilityInfoInDB(const std::string &devic int32_t CapabilityInfoManager::RemoveCapabilityInfoByKey(const std::string &key) { + if (IdLengthInvalid(key)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Remove capability device info, key: %{public}s", GetAnonyString(key).c_str()); std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -288,6 +293,9 @@ int32_t CapabilityInfoManager::RemoveCapabilityInfoByKey(const std::string &key) int32_t CapabilityInfoManager::RemoveCapabilityInfoInMem(const std::string &deviceId) { + if (IdLengthInvalid(deviceId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("remove capability device info in memory, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(capInfoMgrMutex_); for (auto iter = globalCapInfoMap_.begin(); iter != globalCapInfoMap_.end();) { @@ -369,6 +377,9 @@ void CapabilityInfoManager::OnChange(const DistributedKv::DataOrigin &origin, Ke void CapabilityInfoManager::HandleCapabilityAddChange(const std::vector &insertRecords) { + if (RecordSizeInvalid(insertRecords)){ + return; + } std::lock_guard lock(capInfoMgrMutex_); for (const auto &item : insertRecords) { const std::string value = item.value.ToString(); @@ -403,6 +414,9 @@ void CapabilityInfoManager::HandleCapabilityAddChange(const std::vector &updateRecords) { + if (RecordSizeInvalid(updateRecords)){ + return; + } std::lock_guard lock(capInfoMgrMutex_); for (const auto &item : updateRecords) { const std::string value = item.value.ToString(); @@ -419,6 +433,9 @@ void CapabilityInfoManager::HandleCapabilityUpdateChange(const std::vector &deleteRecords) { + if (RecordSizeInvalid(deleteRecords)){ + return; + } std::lock_guard lock(capInfoMgrMutex_); for (const auto &item : deleteRecords) { const std::string value = item.value.ToString(); @@ -458,6 +475,9 @@ bool CapabilityInfoManager::IsCapabilityMatchFilter(const std::shared_ptr> &resInfos) { + if (IdLengthInvalid(deviceId) || RecordSizeInvalid(resInfos)){ + return; + } std::lock_guard lock(capInfoMgrMutex_); for (auto &capabilityInfo : globalCapInfoMap_) { if (IsCapKeyMatchDeviceId(capabilityInfo.first, deviceId)) { @@ -508,6 +531,9 @@ void CapabilityInfoManager::GetCapabilitiesByDeviceId(const std::string &deviceI bool CapabilityInfoManager::HasCapability(const std::string &deviceId, const std::string &dhId) { + if (IdLengthInvalid(deviceId,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); std::string kvKey = GetCapabilityKey(deviceId, dhId); if (globalCapInfoMap_.find(kvKey) == globalCapInfoMap_.end()) { @@ -519,6 +545,9 @@ bool CapabilityInfoManager::HasCapability(const std::string &deviceId, const std int32_t CapabilityInfoManager::GetCapability(const std::string &deviceId, const std::string &dhId, std::shared_ptr &capPtr) { + if (IdLengthInvalid(deviceId,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); std::string key = GetCapabilityKey(deviceId, dhId); if (globalCapInfoMap_.find(key) == globalCapInfoMap_.end()) { @@ -531,6 +560,9 @@ int32_t CapabilityInfoManager::GetCapability(const std::string &deviceId, const int32_t CapabilityInfoManager::GetDataByKey(const std::string &key, std::shared_ptr &capInfoPtr) { + if (IdLengthInvalid(key)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGI("dbAdapterPtr_ is null"); @@ -558,6 +590,9 @@ int32_t CapabilityInfoManager::GetDataByDHType(const DHType dhType, CapabilityIn int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, CapabilityInfoMap &capabilityMap) { + if (IdLengthInvalid(keyPrefix)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); @@ -568,8 +603,7 @@ int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, DHLOGE("Query capability info from db failed, key: %{public}s", GetAnonyString(keyPrefix).c_str()); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (dataVector.size() == 0 || dataVector.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("DataVector size is invalid!"); + if (RecordSizeInvalid(dataVector)){ return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -593,6 +627,9 @@ void CapabilityInfoManager::DumpCapabilityInfos(std::vector &cap std::vector CapabilityInfoManager::GetEntriesByKeys(const std::vector &keys) { + if (ArrayLengthInvalid(keys)){ + return {}; + } DHLOGI("call"); if (keys.empty()) { DHLOGE("keys empty."); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp index 52d1c811..96a1c6a2 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp @@ -18,6 +18,7 @@ #include "capability_info.h" #include "constants.h" #include "distributed_hardware_errno.h" +#include "dh_utils_tool.h" namespace OHOS { namespace DistributedHardware { @@ -31,6 +32,9 @@ std::string GetCapabilityKey(const std::string &deviceId, const std::string &dhI bool IsCapKeyMatchDeviceId(const std::string &key, const std::string &deviceId) { + if (IdLengthInvalid(key,deviceId)){ + return false; + } std::size_t separatorPos = key.find(RESOURCE_SEPARATOR); if (separatorPos == std::string::npos) { return false; diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp index cadc081b..d971aacf 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp @@ -23,6 +23,7 @@ #include "capability_utils.h" #include "constants.h" #include "dh_context.h" +#include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" #include "event_handler.h" @@ -190,6 +191,9 @@ int32_t DBAdapter::ReInit(bool isAutoSync) std::string DBAdapter::GetNetworkIdByKey(const std::string &key) { + if (IdLengthInvalid(key)){ + return ""; + } DHLOGI("Get networkId by key: %{public}s", GetAnonyString(key).c_str()); std::string deviceId = DHContext::GetInstance().GetDeviceIdByDBGetPrefix(key); if (deviceId.empty()) { @@ -217,6 +221,9 @@ std::string DBAdapter::GetNetworkIdByKey(const std::string &key) void DBAdapter::SyncByNotFound(const std::string &key) { + if (IdLengthInvalid(key)){ + return; + } std::string networkId = GetNetworkIdByKey(key); if (networkId.empty()) { DHLOGW("The networkId emtpy."); @@ -232,6 +239,9 @@ void DBAdapter::SyncByNotFound(const std::string &key) int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) { + if (IdLengthInvalid(key) || MessageLengthInvalid(data)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Get data by key: %{public}s, storeId: %{public}s, dataType: %{public}d", GetAnonyString(key).c_str(), storeId_.storeId.c_str(), static_cast(this->dataType)); std::lock_guard lock(dbAdapterMutex_); @@ -262,6 +272,9 @@ int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector &values) { + if (IdLengthInvalid(keyPrefix)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Get data by key prefix: %{public}s, storeId: %{public}s, dataType: %{public}d", GetAnonyString(keyPrefix).c_str(), storeId_.storeId.c_str(), static_cast(this->dataType)); std::lock_guard lock(dbAdapterMutex_); @@ -288,9 +301,8 @@ int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector< GetAnonyString(keyPrefix).c_str()); return ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL; } - if (allEntries.size() == 0 || allEntries.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("AllEntries size is invalid!"); - return ERR_DH_FWK_PARA_INVALID; + if (RecordSizeInvalid(allEntries)){ + return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto& item : allEntries) { values.push_back(item.value.ToString()); @@ -300,8 +312,7 @@ int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector< int32_t DBAdapter::PutData(const std::string &key, const std::string &value) { - if (key.empty() || key.size() > MAX_MESSAGE_LEN || value.empty() || value.size() > MAX_MESSAGE_LEN) { - DHLOGI("Param is invalid!"); + if (IdLengthInvalid(key) || MessageLengthInvalid(value)){ return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(dbAdapterMutex_); @@ -321,6 +332,9 @@ int32_t DBAdapter::PutData(const std::string &key, const std::string &value) int32_t DBAdapter::PutDataBatch(const std::vector &keys, const std::vector &values) { + if (ArrayLengthInvalid(keys) || ArrayLengthInvalid(values)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); @@ -471,6 +485,9 @@ void DBAdapter::DeleteKvStore() int32_t DBAdapter::RemoveDeviceData(const std::string &deviceId) { + if (IdLengthInvalid(deviceId)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); @@ -487,6 +504,9 @@ int32_t DBAdapter::RemoveDeviceData(const std::string &deviceId) int32_t DBAdapter::RemoveDataByKey(const std::string &key) { + if (IdLengthInvalid(key)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); @@ -504,6 +524,9 @@ int32_t DBAdapter::RemoveDataByKey(const std::string &key) std::vector DBAdapter::GetEntriesByKeys(const std::vector &keys) { + if (ArrayLengthInvalid(keys)){ + return {}; + } DHLOGI("call"); std::vector entries; if (keys.empty()) { diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp index 574e9842..828b08bb 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp @@ -83,6 +83,9 @@ int32_t LocalCapabilityInfoManager::UnInit() int32_t LocalCapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &deviceId) { + if (IdLengthInvalid(deviceId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Sync DeviceInfo from DB, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -94,8 +97,7 @@ int32_t LocalCapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &devi DHLOGE("Query data from DB by deviceId failed, id: %{public}s", GetAnonyString(deviceId).c_str()); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (dataVector.size() == 0 || dataVector.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("DataVector size is invalid!"); + if (RecordSizeInvalid(dataVector)){ return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -111,8 +113,7 @@ int32_t LocalCapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &devi int32_t LocalCapabilityInfoManager::AddCapability(const std::vector> &resInfos) { - if (resInfos.size() == 0 || resInfos.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("ResInfos size is invalid!"); + if (RecordSizeInvalid(resInfos)){ return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -146,6 +147,9 @@ int32_t LocalCapabilityInfoManager::AddCapability(const std::vector lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -166,6 +170,9 @@ int32_t LocalCapabilityInfoManager::RemoveCapabilityInfoByKey(const std::string void LocalCapabilityInfoManager::GetCapabilitiesByDeviceId(const std::string &deviceId, std::vector> &resInfos) { + if (IdLengthInvalid(deviceId) || RecordSizeInvalid(resInfos)){ + return; + } std::lock_guard lock(capInfoMgrMutex_); for (auto &capabilityInfo : globalCapInfoMap_) { if (IsCapKeyMatchDeviceId(capabilityInfo.first, deviceId)) { @@ -177,6 +184,9 @@ void LocalCapabilityInfoManager::GetCapabilitiesByDeviceId(const std::string &de int32_t LocalCapabilityInfoManager::GetCapability(const std::string &deviceId, const std::string &dhId, std::shared_ptr &capPtr) { + if (IdLengthInvalid(deviceId,dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); std::string key = GetCapabilityKey(deviceId, dhId); if (globalCapInfoMap_.find(key) == globalCapInfoMap_.end()) { @@ -189,6 +199,9 @@ int32_t LocalCapabilityInfoManager::GetCapability(const std::string &deviceId, c int32_t LocalCapabilityInfoManager::GetDataByKey(const std::string &key, std::shared_ptr &capInfoPtr) { + if (IdLengthInvalid(key)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGI("dbAdapterPtr_ is null"); @@ -216,6 +229,9 @@ int32_t LocalCapabilityInfoManager::GetDataByDHType(const DHType dhType, Capabil int32_t LocalCapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, CapabilityInfoMap &capabilityMap) { + if (KeySizeInvalid(keyPrefix)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); @@ -226,8 +242,7 @@ int32_t LocalCapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPre DHLOGE("Query capability info from db failed, key: %{public}s", GetAnonyString(keyPrefix).c_str()); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (dataVector.size() == 0 || dataVector.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("DataVector size is invalid!"); + if (RecordSizeInvalid(dataVector)){ return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp index 6630e29c..f9ee6392 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp @@ -52,6 +52,9 @@ void MetaCapabilityInfo::SetSinkVersion(const std::string &sinkVersion) int32_t MetaCapabilityInfo::FromJsonString(const std::string &jsonStr) { + if (JsonLengthInvalid(jsonStr)){ + return ERR_DH_FWK_PARA_INVALID; + } cJSON *jsonObj = cJSON_Parse(jsonStr.c_str()); if (jsonObj == NULL) { DHLOGE("jsonStr parse failed"); @@ -143,6 +146,10 @@ std::string MetaCapabilityInfo::GetAnonymousKey() const void ToJson(cJSON *jsonObject, const MetaCapabilityInfo &metaCapInfo) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } cJSON_AddStringToObject(jsonObject, DH_ID.c_str(), metaCapInfo.GetDHId().c_str()); cJSON_AddStringToObject(jsonObject, DEV_ID.c_str(), metaCapInfo.GetDeviceId().c_str()); cJSON_AddStringToObject(jsonObject, DEV_NAME.c_str(), metaCapInfo.GetDeviceName().c_str()); @@ -156,6 +163,10 @@ void ToJson(cJSON *jsonObject, const MetaCapabilityInfo &metaCapInfo) void FromJson(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, DH_ID)) { DHLOGE("DH_ID is invalid!"); return; diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp index 7eddc2ad..0aed4a5f 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp @@ -116,8 +116,7 @@ int32_t MetaInfoManager::UnInit() int32_t MetaInfoManager::AddMetaCapInfos(const std::vector> &metaCapInfos) { - if (metaCapInfos.size() == 0 || metaCapInfos.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("metaCapInfos size is invalid!"); + if (RecordSizeInvalid(metaCapInfos)){ return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } std::lock_guard lock(metaInfoMgrMutex_); @@ -156,6 +155,9 @@ int32_t MetaInfoManager::AddMetaCapInfos(const std::vector lock(metaInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -167,8 +169,7 @@ int32_t MetaInfoManager::SyncMetaInfoFromDB(const std::string &udidHash) DHLOGE("Query Metadata from DB by udidHash failed, udidHash: %{public}s", GetAnonyString(udidHash).c_str()); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (dataVector.size() == 0 || dataVector.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("DataVector size is invalid!"); + if (RecordSizeInvalid(dataVector)){ return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -195,8 +196,7 @@ int32_t MetaInfoManager::SyncRemoteMetaInfos() DHLOGE("Query all Metadata from DB failed"); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (dataVector.size() == 0 || dataVector.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("DataVector size is invalid!"); + if (RecordSizeInvalid(dataVector)){ return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -224,6 +224,9 @@ int32_t MetaInfoManager::SyncRemoteMetaInfos() int32_t MetaInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, MetaCapInfoMap &metaCapMap) { + if (KeySizeInvalid(keyPrefix)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(metaInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); @@ -234,8 +237,7 @@ int32_t MetaInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, MetaCa DHLOGE("Query metaInfo from db failed, keyPrefix: %{public}s", GetAnonyString(keyPrefix).c_str()); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (dataVector.size() == 0 || dataVector.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("DataVector size is invalid!"); + if (RecordSizeInvalid(dataVector)){ return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -251,6 +253,9 @@ int32_t MetaInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, MetaCa int32_t MetaInfoManager::RemoveMetaInfoByKey(const std::string &key) { + if (KeySizeInvalid(key)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Remove device metaInfo, key: %{public}s", GetAnonyString(key).c_str()); std::lock_guard lock(metaInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -269,6 +274,9 @@ int32_t MetaInfoManager::RemoveMetaInfoByKey(const std::string &key) int32_t MetaInfoManager::GetMetaCapInfo(const std::string &udidHash, const std::string &dhId, std::shared_ptr &metaCapPtr) { + if (HashSizeInvalid(udidHash) || IdLengthInvalid(dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(metaInfoMgrMutex_); std::string key = GetCapabilityKey(udidHash, dhId); if (globalMetaInfoMap_.find(key) == globalMetaInfoMap_.end()) { @@ -282,6 +290,9 @@ int32_t MetaInfoManager::GetMetaCapInfo(const std::string &udidHash, void MetaInfoManager::GetMetaCapInfosByUdidHash(const std::string &udidHash, std::vector> &metaCapInfos) { + if (HashSizeInvalid(udidHash)){ + return; + } std::lock_guard lock(metaInfoMgrMutex_); for (auto &metaCapInfo : globalMetaInfoMap_) { if (IsCapKeyMatchDeviceId(metaCapInfo.first, udidHash)) { @@ -292,6 +303,9 @@ void MetaInfoManager::GetMetaCapInfosByUdidHash(const std::string &udidHash, int32_t MetaInfoManager::GetMetaCapByValue(const std::string &value, std::shared_ptr &metaCapPtr) { + if (MessageLengthInvalid(value)){ + return ERR_DH_FWK_PARA_INVALID; + } if (metaCapPtr == nullptr) { metaCapPtr = std::make_shared(); } @@ -347,6 +361,9 @@ void MetaInfoManager::OnChange(const DistributedKv::DataOrigin &origin, Keys &&k void MetaInfoManager::HandleMetaCapabilityAddChange(const std::vector &insertRecords) { + if (RecordSizeInvalid(insertRecords)){ + return; + } std::lock_guard lock(metaInfoMgrMutex_); for (const auto &item : insertRecords) { const std::string value = item.value.ToString(); @@ -381,6 +398,9 @@ void MetaInfoManager::HandleMetaCapabilityAddChange(const std::vector &updateRecords) { + if (RecordSizeInvalid(updateRecords)){ + return; + } std::lock_guard lock(metaInfoMgrMutex_); for (const auto &item : updateRecords) { const std::string value = item.value.ToString(); @@ -397,6 +417,9 @@ void MetaInfoManager::HandleMetaCapabilityUpdateChange(const std::vector &deleteRecords) { + if (RecordSizeInvalid(deleteRecords)){ + return; + } std::lock_guard lock(metaInfoMgrMutex_); for (const auto &item : deleteRecords) { const std::string value = item.value.ToString(); @@ -413,6 +436,9 @@ void MetaInfoManager::HandleMetaCapabilityDeleteChange(const std::vector MetaInfoManager::GetEntriesByKeys(const std::vector &keys) { + if (ArrayLengthInvalid(keys)){ + return {}; + } DHLOGI("call"); if (keys.empty()) { DHLOGE("keys empty."); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp index 6871330b..e6b08acd 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp @@ -32,6 +32,9 @@ namespace DistributedHardware { int32_t VersionInfo::FromJsonString(const std::string &jsonStr) { + if (JsonLengthInvalid(jsonStr)){ + return ERR_DH_FWK_PARA_INVALID; + } cJSON *jsonObj = cJSON_Parse(jsonStr.c_str()); if (jsonObj == NULL) { DHLOGE("json string parse failed"); @@ -63,6 +66,10 @@ std::string VersionInfo::ToJsonString() const void ToJson(cJSON *jsonObject, const VersionInfo &versionInfo) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } cJSON_AddStringToObject(jsonObject, DEV_ID.c_str(), versionInfo.deviceId.c_str()); cJSON_AddStringToObject(jsonObject, DH_VER.c_str(), versionInfo.dhVersion.c_str()); @@ -90,6 +97,10 @@ void ToJson(cJSON *jsonObject, const VersionInfo &versionInfo) void FromJson(const cJSON *jsonObject, CompVersion &compVer) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (IsString(jsonObject, NAME)) { compVer.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; } @@ -110,6 +121,10 @@ void FromJson(const cJSON *jsonObject, CompVersion &compVer) void FromJson(const cJSON *jsonObject, VersionInfo &versionInfo) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (IsString(jsonObject, DEV_ID)) { versionInfo.deviceId = cJSON_GetObjectItem(jsonObject, DEV_ID.c_str())->valuestring; } diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp index b26557e6..61ff6802 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp @@ -138,6 +138,9 @@ int32_t VersionInfoManager::AddVersion(const VersionInfo &versionInfo) int32_t VersionInfoManager::GetVersionInfoByDeviceId(const std::string &deviceId, VersionInfo &versionInfo) { + if (IdLengthInvalid(deviceId)){ + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(verInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr_ is null"); @@ -167,6 +170,9 @@ void VersionInfoManager::UpdateVersionCache(const VersionInfo &versionInfo) int32_t VersionInfoManager::RemoveVersionInfoByDeviceId(const std::string &deviceId) { + if (IdLengthInvalid(deviceId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Remove version device info, key: %{public}s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(verInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -192,6 +198,9 @@ int32_t VersionInfoManager::RemoveVersionInfoByDeviceId(const std::string &devic int32_t VersionInfoManager::SyncVersionInfoFromDB(const std::string &deviceId) { + if (IdLengthInvalid(deviceId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("Sync versionInfo from DB, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); std::lock_guard lock(verInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -227,8 +236,7 @@ int32_t VersionInfoManager::SyncRemoteVersionInfos() DHLOGE("Query all data from DB failed"); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (dataVector.size() == 0 || dataVector.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("DataVector Size is invalid!"); + if (RecordSizeInvalid(dataVector)){ return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -274,6 +282,9 @@ void VersionInfoManager::OnChange(const DistributedKv::ChangeNotification &chang void VersionInfoManager::HandleVersionAddChange(const std::vector &insertRecords) { + if (RecordSizeInvalid(insertRecords)){ + return; + } DHLOGI("Version add change"); for (const auto &item : insertRecords) { const std::string value = item.value.ToString(); @@ -287,6 +298,9 @@ void VersionInfoManager::HandleVersionAddChange(const std::vector &updateRecords) { + if (RecordSizeInvalid(updateRecords)){ + return; + } DHLOGI("Version update change"); for (const auto &item : updateRecords) { const std::string value = item.value.ToString(); @@ -300,6 +314,9 @@ void VersionInfoManager::HandleVersionUpdateChange(const std::vector &deleteRecords) { + if (RecordSizeInvalid(deleteRecords)){ + return; + } DHLOGI("Version delete change"); for (const auto &item : deleteRecords) { const std::string value = item.value.ToString(); diff --git a/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp b/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp index 3998af7e..05df2ed0 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_comm_tool.cpp @@ -197,7 +197,7 @@ void DHCommTool::DHCommToolEventHandler::ProcessFullCapsRsp(const FullCapsRsp &c const std::shared_ptr dhCommToolPtr) { if (capsRsp.networkId.empty() || capsRsp.caps.empty()) { - DHLOGE("Receive remote caps info invalid"); + DHLOGE("Receive remote caps info invalid!"); return; } // after receive rsp, close dsoftbus channel diff --git a/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp b/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp index 90a54bd7..51014589 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp @@ -108,6 +108,9 @@ void DHTransport::OnBytesReceived(int32_t socketId, const void *data, uint32_t d void DHTransport::HandleReceiveMessage(const std::string &payload) { + if (MessageLengthInvalid(payload)){ + return; + } std::string rawPayload = Decompress(payload); cJSON *root = cJSON_Parse(rawPayload.c_str()); @@ -205,6 +208,10 @@ void OnFile(int32_t socket, FileEvent *event) void OnQos(int32_t socket, QoSEvent eventId, const QosTV *qos, uint32_t qosCount) { + if (qosCount < 0 || qosCount > MAX_ROUND_SIZE){ + DHLOGE("qosCount is invalid!"); + return; + } DHLOGI("OnQos, socket: %{public}d, QoSEvent: %{public}d, qosCount: %{public}" PRIu32, socket, (int32_t)eventId, qosCount); for (uint32_t idx = 0; idx < qosCount; idx++) { @@ -241,6 +248,9 @@ int32_t DHTransport::CreateServerSocket() int32_t DHTransport::CreateClientSocket(const std::string &remoteNetworkId) { + if (IdLengthInvalid(remoteNetworkId)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("CreateClientSocket start, peerNetworkId: %{public}s", GetAnonyString(remoteNetworkId).c_str()); std::string peerSocketName = DH_FWK_SESSION_NAME + remoteNetworkId.substr(0, INTERCEPT_STRING_LENGTH); SocketInfo info = { @@ -305,6 +315,9 @@ int32_t DHTransport::UnInit() bool DHTransport::IsDeviceSessionOpened(const std::string &remoteNetworkId, int32_t &socketId) { + if (IdLengthInvalid(remoteNetworkId)){ + return false; + } std::lock_guard lock(rmtSocketIdMtx_); if (remoteDevSocketIds_.find(remoteNetworkId) == remoteDevSocketIds_.end()) { return false; @@ -330,12 +343,18 @@ std::string DHTransport::GetRemoteNetworkIdBySocketId(int32_t socketId) void DHTransport::ClearDeviceSocketOpened(const std::string &remoteDevId) { + if (IdLengthInvalid(remoteDevId)){ + return; + } std::lock_guard lock(rmtSocketIdMtx_); remoteDevSocketIds_.erase(remoteDevId); } int32_t DHTransport::StartSocket(const std::string &remoteNetworkId) { + if (IdLengthInvalid(remoteNetworkId)){ + return ERR_DH_FWK_PARA_INVALID; + } int32_t socketId = -1; if (IsDeviceSessionOpened(remoteNetworkId, socketId)) { DHLOGE("Softbus session has already opened, deviceId: %{public}s", GetAnonyString(remoteNetworkId).c_str()); @@ -371,6 +390,9 @@ int32_t DHTransport::StartSocket(const std::string &remoteNetworkId) int32_t DHTransport::StopSocket(const std::string &remoteNetworkId) { + if (IdLengthInvalid(remoteNetworkId)){ + return ERR_DH_FWK_PARA_INVALID; + } int32_t socketId = -1; if (!IsDeviceSessionOpened(remoteNetworkId, socketId)) { DHLOGI("remote dev may be not opened, remoteNetworkId: %{public}s", GetAnonyString(remoteNetworkId).c_str()); @@ -386,6 +408,9 @@ int32_t DHTransport::StopSocket(const std::string &remoteNetworkId) int32_t DHTransport::Send(const std::string &remoteNetworkId, const std::string &payload) { + if (IdLengthInvalid(remoteNetworkId) || MessageLengthInvalid(payload)){ + return ERR_DH_FWK_PARA_INVALID; + } int32_t socketId = -1; if (!IsDeviceSessionOpened(remoteNetworkId, socketId)) { DHLOGI("The session is not open, target networkId: %{public}s", GetAnonyString(remoteNetworkId).c_str()); diff --git a/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp b/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp index feebd097..467075f5 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp @@ -16,12 +16,17 @@ #include "dh_transport_obj.h" #include "dh_utils_tool.h" +#include "distributed_hardware_log.h" namespace OHOS { namespace DistributedHardware { void ToJson(cJSON *jsonObject, const FullCapsRsp &capsRsp) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } const char *networkId = capsRsp.networkId.c_str(); cJSON_AddStringToObject(jsonObject, CAPS_RSP_NETWORKID_KEY, networkId); cJSON *capArr = cJSON_CreateArray(); @@ -42,6 +47,10 @@ void ToJson(cJSON *jsonObject, const FullCapsRsp &capsRsp) void FromJson(const cJSON *jsonObject, FullCapsRsp &capsRsp) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } std::string keyNetworkId(CAPS_RSP_NETWORKID_KEY); if (IsString(jsonObject, keyNetworkId)) { capsRsp.networkId = cJSON_GetObjectItem(jsonObject, CAPS_RSP_NETWORKID_KEY)->valuestring; @@ -61,6 +70,10 @@ void FromJson(const cJSON *jsonObject, FullCapsRsp &capsRsp) void ToJson(cJSON *jsonObject, const CommMsg &commMsg) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } cJSON_AddNumberToObject(jsonObject, COMM_MSG_CODE_KEY, commMsg.code); const char *msg = commMsg.msg.c_str(); cJSON_AddStringToObject(jsonObject, COMM_MSG_MSG_KEY, msg); @@ -68,6 +81,10 @@ void ToJson(cJSON *jsonObject, const CommMsg &commMsg) void FromJson(const cJSON *jsonObject, CommMsg &commMsg) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } std::string keyCode(COMM_MSG_CODE_KEY); if (IsInt32(jsonObject, keyCode)) { commMsg.code = cJSON_GetObjectItem(jsonObject, COMM_MSG_CODE_KEY)->valueint; diff --git a/services/distributedhardwarefwkservice/src/utils/dh_context.cpp b/services/distributedhardwarefwkservice/src/utils/dh_context.cpp index 0959d953..25df6743 100644 --- a/services/distributedhardwarefwkservice/src/utils/dh_context.cpp +++ b/services/distributedhardwarefwkservice/src/utils/dh_context.cpp @@ -114,8 +114,7 @@ const DeviceInfo& DHContext::GetDeviceInfo() void DHContext::AddOnlineDevice(const std::string &udid, const std::string &uuid, const std::string &networkId) { - if (udid.empty() || uuid.empty() || networkId.empty()) { - DHLOGE("Add online device id invalid"); + if (IdLengthInvalid(udid,uuid,networkId)){ return; } std::unique_lock lock(onlineDevMutex_); @@ -137,6 +136,9 @@ void DHContext::AddOnlineDevice(const std::string &udid, const std::string &uuid void DHContext::RemoveOnlineDeviceByUUID(const std::string &uuid) { + if (IdLengthInvalid(uuid)){ + return; + } std::unique_lock lock(onlineDevMutex_); for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { if (iter->uuid == uuid) { @@ -148,7 +150,7 @@ void DHContext::RemoveOnlineDeviceByUUID(const std::string &uuid) bool DHContext::IsDeviceOnline(const std::string &uuid) { - if (uuid.empty()) { + if (IdLengthInvalid(uuid)) { return false; } std::shared_lock lock(onlineDevMutex_); @@ -170,6 +172,9 @@ size_t DHContext::GetOnlineCount() std::string DHContext::GetNetworkIdByUUID(const std::string &uuid) { + if (IdLengthInvalid(uuid)){ + return ""; + } std::unique_lock lock(onlineDevMutex_); std::string networkId = ""; for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { @@ -183,6 +188,9 @@ std::string DHContext::GetNetworkIdByUUID(const std::string &uuid) std::string DHContext::GetUdidHashIdByUUID(const std::string &uuid) { + if ( IdLengthInvalid(uuid)){ + return ""; + } std::unique_lock lock(onlineDevMutex_); std::string udidHash = ""; for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { @@ -196,6 +204,9 @@ std::string DHContext::GetUdidHashIdByUUID(const std::string &uuid) std::string DHContext::GetUUIDByNetworkId(const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return ""; + } std::unique_lock lock(onlineDevMutex_); std::string uuid = ""; for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { @@ -209,6 +220,9 @@ std::string DHContext::GetUUIDByNetworkId(const std::string &networkId) std::string DHContext::GetUDIDByNetworkId(const std::string &networkId) { + if (IdLengthInvalid(networkId)){ + return ""; + } std::unique_lock lock(onlineDevMutex_); std::string udid = ""; for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { @@ -222,6 +236,9 @@ std::string DHContext::GetUDIDByNetworkId(const std::string &networkId) std::string DHContext::GetUUIDByDeviceId(const std::string &deviceId) { + if (IdLengthInvalid(deviceId)){ + return ""; + } std::unique_lock lock(onlineDevMutex_); std::string uuid = ""; for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { @@ -235,6 +252,9 @@ std::string DHContext::GetUUIDByDeviceId(const std::string &deviceId) std::string DHContext::GetNetworkIdByDeviceId(const std::string &deviceId) { + if (IdLengthInvalid(deviceId)){ + return ""; + } std::unique_lock lock(onlineDevMutex_); std::string networkId = ""; for (auto iter = devIdEntrySet_.begin(); iter != devIdEntrySet_.end(); iter++) { @@ -248,6 +268,9 @@ std::string DHContext::GetNetworkIdByDeviceId(const std::string &deviceId) std::string DHContext::GetDeviceIdByDBGetPrefix(const std::string &prefix) { + if (IdLengthInvalid(prefix)){ + return ""; + } std::string id = ""; if (prefix.empty()) { return id; @@ -274,15 +297,14 @@ void DHContext::RegisDHFWKIsomerismListener() void DHContext::DHFWKIsomerismListener::OnMessage(const DHTopic topic, const std::string &message) { + if (MessageLengthInvalid(message)){ + return; + } DHLOGI("OnMessage topic: %{public}u", static_cast(topic)); if (topic != DHTopic::TOPIC_ISOMERISM) { DHLOGE("OnMessage topic is wrong"); return; } - if (message.length() > MAX_MESSAGE_LEN) { - DHLOGE("OnMessage error, message too large"); - return; - } cJSON *messageJson = cJSON_Parse(message.c_str()); if (messageJson == nullptr) { DHLOGE("OnMessage error, parse failed"); @@ -313,6 +335,9 @@ void DHContext::DHFWKIsomerismListener::OnMessage(const DHTopic topic, const std void DHContext::AddIsomerismConnectDev(const std::string &IsomerismDeviceId) { + if (IdLengthInvalid(IsomerismDeviceId)){ + return; + } DHLOGI("AddIsomerismConnectDev id = %{public}s", GetAnonyString(IsomerismDeviceId).c_str()); std::shared_lock lock(connectDevMutex_); connectedDevIds_.insert(IsomerismDeviceId); @@ -320,6 +345,9 @@ void DHContext::AddIsomerismConnectDev(const std::string &IsomerismDeviceId) void DHContext::DelIsomerismConnectDev(const std::string &IsomerismDeviceId) { + if (IdLengthInvalid(IsomerismDeviceId)){ + return; + } DHLOGI("DelIsomerismConnectDev id = %{public}s", GetAnonyString(IsomerismDeviceId).c_str()); std::shared_lock lock(connectDevMutex_); if (connectedDevIds_.find(IsomerismDeviceId) == connectedDevIds_.end()) { diff --git a/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp b/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp index 8cd7b034..38d6b52f 100644 --- a/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp +++ b/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp @@ -19,6 +19,7 @@ #include "component_loader.h" #include "dh_context.h" #include "distributed_hardware_log.h" +#include "dh_utils_tool.h" namespace OHOS { namespace DistributedHardware { @@ -60,6 +61,9 @@ void VersionManager::ShowLocalVersion(const DHVersion &dhVersion) const int32_t VersionManager::AddDHVersion(const std::string &uuid, const DHVersion &dhVersion) { + if (IdLengthInvalid(uuid)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("addDHVersion uuid: %{public}s", GetAnonyString(uuid).c_str()); std::lock_guard lock(versionMutex_); dhVersions_[uuid] = dhVersion; @@ -68,6 +72,9 @@ int32_t VersionManager::AddDHVersion(const std::string &uuid, const DHVersion &d int32_t VersionManager::RemoveDHVersion(const std::string &uuid) { + if (IdLengthInvalid(uuid)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("uuid: %{public}s", GetAnonyString(uuid).c_str()); std::lock_guard lock(versionMutex_); std::unordered_map::iterator iter = dhVersions_.find(uuid); @@ -81,6 +88,9 @@ int32_t VersionManager::RemoveDHVersion(const std::string &uuid) int32_t VersionManager::GetDHVersion(const std::string &uuid, DHVersion &dhVersion) { + if (IdLengthInvalid(uuid)){ + return ERR_DH_FWK_PARA_INVALID; + } DHLOGI("uuid: %{public}s", GetAnonyString(uuid).c_str()); std::lock_guard lock(versionMutex_); std::unordered_map::iterator iter = dhVersions_.find(uuid); @@ -95,6 +105,9 @@ int32_t VersionManager::GetDHVersion(const std::string &uuid, DHVersion &dhVersi int32_t VersionManager::GetCompVersion(const std::string &uuid, const DHType dhType, CompVersion &compVersion) { + if (IdLengthInvalid(uuid)){ + return ERR_DH_FWK_PARA_INVALID; + } DHVersion dhVersion; int32_t ret = GetDHVersion(uuid, dhVersion); if (ret != DH_FWK_SUCCESS) { diff --git a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp index ef388b0d..a00e2882 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp @@ -15,6 +15,7 @@ #include "mock_hardware_handler.h" +#include "distributed_hardware_log.h" #include "distributed_hardware_errno.h" namespace OHOS { @@ -60,6 +61,9 @@ void MockHardwareHandler::UnRegisterPluginListener() int32_t MockHardwareHandler::PluginHardware(const std::string &dhId, const std::string &attr, const std::string &subtype) { + if (IdLengthInvalid(dhId)){ + return ERR_DH_FWK_PARA_INVALID; + } if (listener_ != nullptr) { listener_->PluginHardware(dhId, attr, subtype); } @@ -68,6 +72,9 @@ int32_t MockHardwareHandler::PluginHardware(const std::string &dhId, const std:: int32_t MockHardwareHandler::UnPluginHardware(const std::string &dhId) { + if (HashSizeInvalid(udidHash)){ + return ERR_DH_FWK_PARA_INVALID; + } if (listener_ != nullptr) { listener_->UnPluginHardware(dhId); } diff --git a/utils/include/dh_utils_tool.h b/utils/include/dh_utils_tool.h index c52e1c45..aec852df 100644 --- a/utils/include/dh_utils_tool.h +++ b/utils/include/dh_utils_tool.h @@ -65,6 +65,23 @@ std::string Compress(const std::string& data); std::string Decompress(const std::string& data); bool GetSysPara(const char *key, bool &value); + +template +bool IdLengthInvalid(const Args &...args); + +bool MessageLengthInvalid(const std::string &input); + +template +bool RecordSizeInvalid(const std::vector &input); + +bool JsonLengthInvalid(const std::string &jsonStr); + +template +bool ArrayLengthInvalid(const std::vector &array); + +bool KeySizeInvalid(const std::string &key); + +bool HashSizeInvalid(const std::string &hashValue); } // namespace DistributedHardware } // namespace OHOS #endif diff --git a/utils/src/anonymous_string.cpp b/utils/src/anonymous_string.cpp index c5491d12..bcef3853 100644 --- a/utils/src/anonymous_string.cpp +++ b/utils/src/anonymous_string.cpp @@ -19,6 +19,10 @@ #include #include "securec.h" +#include "constants.h" +#include "distributed_hardware_errno.h" +#include "distributed_hardware_log.h" +#include "dh_utils_tool.h" namespace OHOS { namespace DistributedHardware { @@ -30,7 +34,7 @@ namespace { } std::string GetAnonyString(const std::string &value) { - if (value.empty()) { + if (MessageLengthInvalid(value)){ return ""; } std::string res; diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index be684494..40ce2d7e 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -82,9 +82,6 @@ std::string GetRandomID() std::string GetUUIDByDm(const std::string &networkId) { - if (networkId.empty()) { - return ""; - } std::string uuid = ""; auto ret = DeviceManager::GetInstance().GetUuidByNetworkId(DH_FWK_PKG_NAME, networkId, uuid); return (ret == DH_FWK_SUCCESS) ? uuid : ""; @@ -92,9 +89,6 @@ std::string GetUUIDByDm(const std::string &networkId) std::string GetUDIDByDm(const std::string &networkId) { - if (networkId.empty()) { - return ""; - } std::string udid = ""; auto ret = DeviceManager::GetInstance().GetUdidByNetworkId(DH_FWK_PKG_NAME, networkId, udid); return (ret == DH_FWK_SUCCESS) ? udid : ""; @@ -102,10 +96,6 @@ std::string GetUDIDByDm(const std::string &networkId) std::string GetDeviceIdByUUID(const std::string &uuid) { - if (uuid.size() == 0 || uuid.size() > MAX_ID_LEN) { - DHLOGE("uuid is invalid!"); - return ""; - } return Sha256(uuid); } @@ -286,5 +276,81 @@ bool GetSysPara(const char *key, bool &value) valueStr >> std::boolalpha >> value; return true; } + +template +bool IdLengthInvalid(const Args &...args) +{ + std::vector flag{ args.empty()..., (args.length() > MAX_ID_LEN)... }; + + if (std::all_of(flag.begin(),flag.end(),[](bool i) {return !i; })) { + return false; + } + else { + DHLOGE("On parameter length error, maybe empty or beyond MAX_ID_LEN!"); + return true; + } +} + +bool MessageLengthInvalid(const std::string &input) +{ + if (input.empty() || input.length() > MAX_MESSAGE_LEN){ + DHLOGE("On parameter error, maybe empty or beyond MAX_MESSAGE_LEN!"); + return true; + }else{ + return false; + } +} + +template +bool RecordSizeInvalid(const std::vector &input) +{ + if (input.empty() || input.size() > MAX_DB_RECORD_SIZE){ + DHLOGE("On parameter error, maybe empty or beyond MAX_DE_RECORD_SIZE!"); + return true; + }else{ + return false; + } +} + +bool JsonLengthInvalid(const std::string &jsonStr) +{ + if (jsonStr.empty() || jsonStr.length() > MAX_JSON_SIZE){ + DHLOGE("On parameter error, maybe empty or beyond MAX_JSON_SIZE"); + return true; + }else{ + return false; + } +} + +template +bool ArrayLengthInvalid(const std::vector &array) +{ + if (array.empty() || array.size() > MAX_ARR_SIZE){ + DHLOGE("On parameter error, maybe empty or beyond MAX_ARR_SIZE"); + return true; + }else{ + return false; + } +} + +bool KeySizeInvalid(const std::string &key) +{ + if (key.empty() || key.length() > MAX_KEY_SIZE){ + DHLOGE("On parameter error, maybe empty or beyond MAX_KEY_SIZE"); + return true; + }else{ + return false; + } +} + +bool HashSizeInvalid(const std::string &hashValue) +{ + if (hashValue.empty() || hashValue.length() > MAX_HASH_SIZE){ + DHLOGE("On parameter error, maybe empty or beyond MAX_HASH_SIZE"); + return true; + }else{ + return false; + } +} } // namespace DistributedHardware } // namespace OHOS diff --git a/utils/src/histreamer_ability_parser.cpp b/utils/src/histreamer_ability_parser.cpp index a9631116..ee59c2ca 100644 --- a/utils/src/histreamer_ability_parser.cpp +++ b/utils/src/histreamer_ability_parser.cpp @@ -37,6 +37,10 @@ static const std::string VIDEO_BIT_STREAM_FMT = "vd_bit_stream_fmt"; void FromJson(const cJSON *jsonObject, AudioEncoderIn &audioEncoderIn) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { DHLOGE("AudioEncoderIn MIME is invalid!\n"); return; @@ -59,26 +63,30 @@ void FromJson(const cJSON *jsonObject, AudioEncoderIn &audioEncoderIn) void FromJson(const cJSON *jsonObject, AudioEncoderOut &audioEncoderOut) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { DHLOGE("AudioEncoderOut MIME is invalid!"); return; } audioEncoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; if (!IsUInt32(jsonObject, AD_MPEG_VER)) { - DHLOGE("AudioEncoderOut AD_MPEG_VER is invalid"); + DHLOGE("AudioEncoderOut AD_MPEG_VER is invalid!"); return; } audioEncoderOut.ad_mpeg_ver = (uint32_t)cJSON_GetObjectItem(jsonObject, AD_MPEG_VER.c_str())->valuedouble; if (!IsUInt8(jsonObject, AUDIO_AAC_PROFILE)) { - DHLOGE("AudioEncoderOut AUDIO_AAC_PROFILE is invalid"); + DHLOGE("AudioEncoderOut AUDIO_AAC_PROFILE is invalid!"); return; } audioEncoderOut.aac_profile = (AudioAacProfile)cJSON_GetObjectItem(jsonObject, AUDIO_AAC_PROFILE.c_str())->valuedouble; if (!IsUInt8(jsonObject, AUDIO_AAC_STREAM_FORMAT)) { - DHLOGE("AudioEncoderOut AUDIO_AAC_STREAM_FORMAT is invalid"); + DHLOGE("AudioEncoderOut AUDIO_AAC_STREAM_FORMAT is invalid!"); return; } audioEncoderOut.aac_stm_fmt = @@ -87,14 +95,18 @@ void FromJson(const cJSON *jsonObject, AudioEncoderOut &audioEncoderOut) void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, NAME)) { - DHLOGE("AudioEncoder NAME is invalid"); + DHLOGE("AudioEncoder NAME is invalid!"); return; } audioEncoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; if (!IsArray(jsonObject, INS)) { - DHLOGE("AudioEncoder INS is invalid"); + DHLOGE("AudioEncoder INS is invalid!"); return; } cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); @@ -106,7 +118,7 @@ void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder) } if (!IsArray(jsonObject, OUTS)) { - DHLOGE("AudioEncoder OUTS is invalid"); + DHLOGE("AudioEncoder OUTS is invalid!"); return; } cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); @@ -120,14 +132,18 @@ void FromJson(const cJSON *jsonObject, AudioEncoder &audioEncoder) void FromJson(const cJSON *jsonObject, AudioDecoderIn &audioDecoderIn) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { - DHLOGE("AudioDecoderIn MIME is invalid"); + DHLOGE("AudioDecoderIn MIME is invalid!"); return; } audioDecoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; if (!IsArray(jsonObject, AUDIO_CHANNEL_LAYOUT)) { - DHLOGE("AudioDecoder AUDIO_CHANNEL_LAYOUT is invalid"); + DHLOGE("AudioDecoder AUDIO_CHANNEL_LAYOUT is invalid!"); return; } const cJSON *channelLayoutJson = cJSON_GetObjectItem(jsonObject, AUDIO_CHANNEL_LAYOUT.c_str()); @@ -139,13 +155,17 @@ void FromJson(const cJSON *jsonObject, AudioDecoderIn &audioDecoderIn) void FromJson(const cJSON *jsonObject, AudioDecoderOut &audioDecoderOut) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { - DHLOGE("AudioDecoderOut MIME is invalid"); + DHLOGE("AudioDecoderOut MIME is invalid!"); return; } audioDecoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; if (!IsArray(jsonObject, AUDIO_SAMPLE_FORMAT)) { - DHLOGE("AudioDecoderOut AUDIO_SAMPLE_FORMAT is invalid"); + DHLOGE("AudioDecoderOut AUDIO_SAMPLE_FORMAT is invalid!"); return; } cJSON *sampleFormatJson = cJSON_GetObjectItem(jsonObject, AUDIO_SAMPLE_FORMAT.c_str()); @@ -157,14 +177,18 @@ void FromJson(const cJSON *jsonObject, AudioDecoderOut &audioDecoderOut) void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, NAME)) { - DHLOGE("AudioDecoderOut MIME is invalid"); + DHLOGE("AudioDecoderOut MIME is invalid!"); return; } audioDecoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; if (!IsArray(jsonObject, INS)) { - DHLOGE("AudioDecoder OUTS is invalid"); + DHLOGE("AudioDecoder OUTS is invalid!"); return; } const cJSON *insJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); @@ -175,7 +199,7 @@ void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder) audioDecoder.ins.push_back(in); } if (!IsArray(jsonObject, OUTS)) { - DHLOGE("AudioDecoder OUTS is invalid"); + DHLOGE("AudioDecoder OUTS is invalid!"); return; } cJSON *outsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); @@ -189,14 +213,18 @@ void FromJson(const cJSON *jsonObject, AudioDecoder &audioDecoder) void FromJson(const cJSON *jsonObject, VideoEncoderIn &videoEncoderIn) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { - DHLOGE("VideoEncoderIn MIME is invalid"); + DHLOGE("VideoEncoderIn MIME is invalid!"); return; } videoEncoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; if (!IsArray(jsonObject, VIDEO_PIXEL_FMT)) { - DHLOGE("VideoEncoderIn VIDEO_PIXEL_FMT is invalid"); + DHLOGE("VideoEncoderIn VIDEO_PIXEL_FMT is invalid!"); return; } cJSON *videoPixelFmt = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str()); @@ -208,8 +236,12 @@ void FromJson(const cJSON *jsonObject, VideoEncoderIn &videoEncoderIn) void FromJson(const cJSON *jsonObject, VideoEncoderOut &videoEncoderOut) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { - DHLOGE("VideoEncoderIn MIME is invalid"); + DHLOGE("VideoEncoderIn MIME is invalid!"); return; } videoEncoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; @@ -217,14 +249,18 @@ void FromJson(const cJSON *jsonObject, VideoEncoderOut &videoEncoderOut) void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, NAME)) { - DHLOGE("VideoEncoder NAME is invalid"); + DHLOGE("VideoEncoder NAME is invalid!"); return; } videoEncoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; if (!IsArray(jsonObject, INS)) { - DHLOGE("VideoEncoder INS is invalid"); + DHLOGE("VideoEncoder INS is invalid!"); return; } cJSON *videoEncoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); @@ -236,7 +272,7 @@ void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder) } if (!IsArray(jsonObject, OUTS)) { - DHLOGE("VideoEncoder OUTS is invalid"); + DHLOGE("VideoEncoder OUTS is invalid!"); return; } cJSON *videoEncoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); @@ -250,14 +286,18 @@ void FromJson(const cJSON *jsonObject, VideoEncoder &videoEncoder) void FromJson(const cJSON *jsonObject, VideoDecoderIn &videoDecoderIn) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { - DHLOGE("VideoDecoderIn MIME is invalid"); + DHLOGE("VideoDecoderIn MIME is invalid!"); return; } videoDecoderIn.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; if (!IsArray(jsonObject, VIDEO_BIT_STREAM_FMT)) { - DHLOGE("VideoDecoderIn VIDEO_BIT_STREAM_FMT is invalid"); + DHLOGE("VideoDecoderIn VIDEO_BIT_STREAM_FMT is invalid!"); return; } cJSON *videoBitStreamFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_BIT_STREAM_FMT.c_str()); @@ -269,14 +309,18 @@ void FromJson(const cJSON *jsonObject, VideoDecoderIn &videoDecoderIn) void FromJson(const cJSON *jsonObject, VideoDecoderOut &videoDecoderOut) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, MIME)) { - DHLOGE("VideoDecoderOut MIME is invalid"); + DHLOGE("VideoDecoderOut MIME is invalid!"); return; } videoDecoderOut.mime = cJSON_GetObjectItem(jsonObject, MIME.c_str())->valuestring; if (!IsArray(jsonObject, VIDEO_BIT_STREAM_FMT)) { - DHLOGE("videoDecoderOut VIDEO_PIXEL_FMT is invalid"); + DHLOGE("videoDecoderOut VIDEO_PIXEL_FMT is invalid!"); return; } cJSON *videoPixelFmtJson = cJSON_GetObjectItem(jsonObject, VIDEO_PIXEL_FMT.c_str()); @@ -288,14 +332,18 @@ void FromJson(const cJSON *jsonObject, VideoDecoderOut &videoDecoderOut) void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } if (!IsString(jsonObject, NAME)) { - DHLOGE("VideoDecoder NAME is invalid"); + DHLOGE("VideoDecoder NAME is invalid!"); return; } videoDecoder.name = cJSON_GetObjectItem(jsonObject, NAME.c_str())->valuestring; if (!IsArray(jsonObject, INS)) { - DHLOGE("VideoDecoder INS is invalid"); + DHLOGE("VideoDecoder INS is invalid!"); return; } cJSON *videoDecoderInsJson = cJSON_GetObjectItem(jsonObject, INS.c_str()); @@ -307,7 +355,7 @@ void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder) } if (!IsArray(jsonObject, OUTS)) { - DHLOGE("VideoDecoder OUTS is invalid"); + DHLOGE("VideoDecoder OUTS is invalid!"); return; } cJSON *videoDecoderOutsJson = cJSON_GetObjectItem(jsonObject, OUTS.c_str()); @@ -322,6 +370,10 @@ void FromJson(const cJSON *jsonObject, VideoDecoder &videoDecoder) template void FromJson(const std::string &key, const cJSON *jsonObject, std::vector &objs) { + if (jsonObject == nullptr) { + DHLOGE("Json pointer is nullptr!"); + return; + } cJSON *json = cJSON_GetObjectItem(jsonObject, key.c_str()); if (json == NULL) { DHLOGE("JSONObject key invalid, key: %{public}s", key.c_str()); -- Gitee From c8b44490e45fdc7563a1b6df32f7d4f732f0703a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Thu, 18 Jul 2024 17:30:11 +0800 Subject: [PATCH 2/6] alter according to AI check MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- .../src/distributed_hardware_fwk_kit.cpp | 8 ++-- .../inner_kits/src/ipc/dhfwk_sa_manager.cpp | 4 +- .../src/ipc/distributed_hardware_proxy.cpp | 6 +-- .../src/accessmanager/access_manager.cpp | 4 +- .../src/componentloader/component_loader.cpp | 4 +- .../componentmanager/component_disable.cpp | 4 +- .../src/componentmanager/component_enable.cpp | 4 +- .../componentmanager/component_manager.cpp | 32 ++++++++-------- .../componentmanager/component_monitor.cpp | 4 +- .../componentmanager/component_privacy.cpp | 8 ++-- .../dh_data_sync_trigger_listener.cpp | 2 +- .../componentmanager/dh_state_listener.cpp | 2 +- .../src/distributed_hardware_manager.cpp | 4 +- .../distributed_hardware_manager_factory.cpp | 4 +- .../src/distributed_hardware_service.cpp | 6 +-- .../src/hidumphelper/enabled_comps_dump.cpp | 4 +- .../local_hardware_manager.cpp | 2 +- .../plugin_listener_impl.cpp | 2 +- .../src/lowlatency/low_latency_listener.cpp | 2 +- .../src/publisher/publisher_item.cpp | 2 +- .../src/resourcemanager/capability_info.cpp | 2 +- .../capability_info_manager.cpp | 38 +++++++++---------- .../src/resourcemanager/capability_utils.cpp | 2 +- .../src/resourcemanager/db_adapter.cpp | 20 +++++----- .../local_capability_info_manager.cpp | 18 ++++----- .../resourcemanager/meta_capability_info.cpp | 2 +- .../src/resourcemanager/meta_info_manager.cpp | 28 +++++++------- .../src/resourcemanager/version_info.cpp | 2 +- .../resourcemanager/version_info_manager.cpp | 14 +++---- .../src/transport/dh_transport.cpp | 14 +++---- .../src/utils/dh_context.cpp | 24 ++++++------ .../src/versionmanager/version_manager.cpp | 8 ++-- .../src/mock_hardware_handler.cpp | 4 +- utils/include/dh_utils_tool.h | 3 +- utils/src/anonymous_string.cpp | 2 +- utils/src/dh_utils_tool.cpp | 31 ++++++++------- 36 files changed, 161 insertions(+), 159 deletions(-) diff --git a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp index b9ac608f..01affc08 100644 --- a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp +++ b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp @@ -90,7 +90,7 @@ int32_t DistributedHardwareFwkKit::PublishMessage(const DHTopic topic, const std DHLOGE("Topic invalid, topic: %{public}" PRIu32, (uint32_t)topic); return ERR_DH_FWK_PARA_INVALID; } - if (MessageLengthInvalid(message)){ + if (MessageLengthInvalid(message)) { return ERR_DH_FWK_PARA_INVALID; } @@ -203,7 +203,7 @@ int32_t DistributedHardwareFwkKit::RegisterCtlCenterCallback(int32_t engineId, int32_t DistributedHardwareFwkKit::PauseDistributedHardware(DHType dhType, const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Pause distributed hardware dhType %{public}u, networkId %{public}s", (uint32_t)dhType, @@ -220,7 +220,7 @@ int32_t DistributedHardwareFwkKit::PauseDistributedHardware(DHType dhType, const int32_t DistributedHardwareFwkKit::ResumeDistributedHardware(DHType dhType, const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Resume distributed hardware dhType %{public}u, networkId %{public}s", (uint32_t)dhType, @@ -237,7 +237,7 @@ int32_t DistributedHardwareFwkKit::ResumeDistributedHardware(DHType dhType, cons int32_t DistributedHardwareFwkKit::StopDistributedHardware(DHType dhType, const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Stop distributed hardware dhType %{public}u, networkId %{public}s", (uint32_t)dhType, diff --git a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp index da5d299c..547ed76f 100644 --- a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp +++ b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp @@ -103,7 +103,7 @@ void DHFWKSAManager::RegisterSAStateCallback(DHFWKSAStateCb callback) void DHFWKSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { - if (IdLengthInvalid(deviceId)){ + if (IdLengthInvalid(deviceId)) { return; } (void)deviceId; @@ -127,7 +127,7 @@ void DHFWKSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbi void DHFWKSAManager::SystemAbilityListener::OnRemoveSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { - if (IdLengthInvalid(deviceId)){ + if (IdLengthInvalid(deviceId)) { return; } (void)deviceId; diff --git a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp index aeb06219..8054a022 100644 --- a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp +++ b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp @@ -416,7 +416,7 @@ int32_t DistributedHardwareProxy::NotifySourceRemoteSinkStarted(std::string &dev int32_t DistributedHardwareProxy::PauseDistributedHardware(DHType dhType, const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } sptr remote = Remote(); @@ -454,7 +454,7 @@ int32_t DistributedHardwareProxy::PauseDistributedHardware(DHType dhType, const int32_t DistributedHardwareProxy::ResumeDistributedHardware(DHType dhType, const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } sptr remote = Remote(); @@ -492,7 +492,7 @@ int32_t DistributedHardwareProxy::ResumeDistributedHardware(DHType dhType, const int32_t DistributedHardwareProxy::StopDistributedHardware(DHType dhType, const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } sptr remote = Remote(); diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index 9bb8b2c9..5ae3bd7e 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -132,7 +132,7 @@ void AccessManager::OnDeviceOffline(const DmDeviceInfo &deviceInfo) auto networkId = std::string(deviceInfo.networkId); std::string uuid = DHContext::GetInstance().GetUUIDByNetworkId(networkId); std::string udid = DHContext::GetInstance().GetUDIDByNetworkId(networkId); - if (IdLengthInvalid(networkId,uuid,udid)){ + if (IdLengthInvalid(networkId, uuid, udid)) { return; } @@ -152,7 +152,7 @@ void AccessManager::OnDeviceReady(const DmDeviceInfo &deviceInfo) auto networkId = std::string(deviceInfo.networkId); auto uuid = GetUUIDByDm(networkId); auto udid = GetUDIDByDm(networkId); - if (IdLengthInvalid(networkId,uuid,udid)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(uuid) || IdLengthInvalid(udid)) { return; } auto ret = diff --git a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp index c6d68fb7..4206bc7e 100644 --- a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp +++ b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp @@ -252,7 +252,7 @@ bool ComponentLoader::CheckComponentEnable(const CompConfig &config) int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std::map &dhtypeMap) { - if (JsonLengthInvalid(jsonStr)){ + if (JsonLengthInvalid(jsonStr)) { return ERR_DH_FWK_PARA_INVALID; } cJSON *root = cJSON_Parse(jsonStr.c_str()); @@ -517,7 +517,7 @@ int32_t ComponentLoader::ParseConfig() } std::string componentProfilePath(path); std::string jsonStr = Readfile(componentProfilePath); - if (MessageLengthInvalid(jsonStr)){ + if (MessageLengthInvalid(jsonStr)) { return ERR_DH_FWK_LOADER_CONFIG_JSON_INVALID; } ret = GetCompPathAndVersion(jsonStr, dhtypeMap); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_disable.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_disable.cpp index 2732452c..cc949dee 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_disable.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_disable.cpp @@ -34,7 +34,7 @@ ComponentDisable::~ComponentDisable() {} int32_t ComponentDisable::Disable(const std::string &networkId, const std::string &dhId, IDistributedHardwareSource *handler) { - if (IdLengthInvalid(networkId,dhId)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGD("networkId = %{public}s dhId = %{public}s.", GetAnonyString(networkId).c_str(), @@ -72,7 +72,7 @@ int32_t ComponentDisable::Disable(const std::string &networkId, const std::strin int32_t ComponentDisable::OnUnregisterResult(const std::string &networkId, const std::string &dhId, int32_t status, const std::string &data) { - if (IdLengthInvalid(networkId,dhId)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } if (status == DH_FWK_SUCCESS) { diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_enable.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_enable.cpp index 1bd66eb8..87715b6c 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_enable.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_enable.cpp @@ -34,7 +34,7 @@ ComponentEnable::~ComponentEnable() {} int32_t ComponentEnable::Enable(const std::string &networkId, const std::string &dhId, const EnableParam ¶m, IDistributedHardwareSource *handler) { - if (IdLengthInvalid(networkId,dhId)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGD("networkId = %{public}s dhId = %{public}s.", GetAnonyString(networkId).c_str(), @@ -72,7 +72,7 @@ int32_t ComponentEnable::Enable(const std::string &networkId, const std::string int32_t ComponentEnable::OnRegisterResult(const std::string &networkId, const std::string &dhId, int32_t status, const std::string &data) { - if (IdLengthInvalid(networkId,dhId)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } if (status == DH_FWK_SUCCESS) { diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 1c226221..815ae4d1 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -516,7 +516,7 @@ bool ComponentManager::InitCompSink() int32_t ComponentManager::Enable(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType) { - if (IdLengthInvalid(networkId,uuid,dhId)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(uuid) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("start."); @@ -574,7 +574,7 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string int32_t ComponentManager::RetryGetEnableParam(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType, EnableParam ¶m) { - if (IdLengthInvalid(networkId,uuid,dhId)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(uuid) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } for (int32_t retryCount = 0; retryCount < ENABLE_RETRY_MAX_TIMES; retryCount++) { @@ -596,7 +596,7 @@ int32_t ComponentManager::RetryGetEnableParam(const std::string &networkId, cons int32_t ComponentManager::Disable(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType) { - if (IdLengthInvalid(networkId,uuid,dhId)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(uuid) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } auto find = compSource_.find(dhType); @@ -645,7 +645,7 @@ DHType ComponentManager::GetDHType(const std::string &uuid, const std::string &d int32_t ComponentManager::GetEnableCapParam(const std::string &networkId, const std::string &uuid, DHType dhType, EnableParam ¶m, std::shared_ptr &capability) { - if (IdLengthInvalid(networkId,uuid)){ + if (IdLengthInvalid(networkId,uuid)) { return ERR_DH_FWK_PARA_INVALID; } DeviceInfo sourceDeviceInfo = GetLocalDeviceInfo(); @@ -694,7 +694,7 @@ int32_t ComponentManager::GetEnableCapParam(const std::string &networkId, const int32_t ComponentManager::GetEnableMetaParam(const std::string &networkId, const std::string &uuid, DHType dhType, EnableParam ¶m, std::shared_ptr &metaCapPtr) { - if (IdLengthInvalid(networkId,uuid)){ + if (IdLengthInvalid(networkId,uuid)) { return ERR_DH_FWK_PARA_INVALID; } DeviceInfo sourceDeviceInfo = GetLocalDeviceInfo(); @@ -729,7 +729,7 @@ int32_t ComponentManager::GetEnableMetaParam(const std::string &networkId, const int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string &dhId, std::shared_ptr &capability) { - if (IdLengthInvalid(uuid,dhId)){ + if (IdLengthInvalid(uuid,dhId)) { return ERR_DH_FWK_PARA_INVALID; } std::string deviceId = GetDeviceIdByUUID(uuid); @@ -753,7 +753,7 @@ int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string int32_t ComponentManager::GetMetaParam(const std::string &uuid, const std::string &dhId, std::shared_ptr &metaCapPtr) { - if (IdLengthInvalid(uuid,dhId)){ + if (IdLengthInvalid(uuid,dhId)) { return ERR_DH_FWK_PARA_INVALID; } auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(DHContext::GetInstance().GetUdidHashIdByUUID(uuid), @@ -769,7 +769,7 @@ int32_t ComponentManager::GetMetaParam(const std::string &uuid, const std::strin int32_t ComponentManager::GetEnableParam(const std::string &networkId, const std::string &uuid, const std::string &dhId, DHType dhType, EnableParam ¶m) { - if (IdLengthInvalid(networkId,uuid,dhId)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(uuid) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("GetEnableParam start, networkId= %{public}s, uuid = %{public}s, dhId = %{public}s, dhType = %{public}#X,", @@ -798,7 +798,7 @@ int32_t ComponentManager::GetEnableParam(const std::string &networkId, const std int32_t ComponentManager::GetVersionFromVerMgr(const std::string &uuid, const DHType dhType, std::string &version, bool isSink) { - if (IdLengthInvalid(uuid)){ + if (IdLengthInvalid(uuid)) { return ERR_DH_FWK_PARA_INVALID; } CompVersion compversion; @@ -818,7 +818,7 @@ int32_t ComponentManager::GetVersionFromVerMgr(const std::string &uuid, const DH int32_t ComponentManager::GetVersionFromVerInfoMgr(const std::string &uuid, const DHType dhType, std::string &version, bool isSink) { - if (IdLengthInvalid(uuid)){ + if (IdLengthInvalid(uuid)) { return ERR_DH_FWK_PARA_INVALID; } VersionInfo versionInfo; @@ -843,7 +843,7 @@ int32_t ComponentManager::GetVersionFromVerInfoMgr(const std::string &uuid, cons int32_t ComponentManager::GetVersion(const std::string &uuid, DHType dhType, std::string &version, bool isSink) { - if (IdLengthInvalid(uuid)){ + if (IdLengthInvalid(uuid)) { return ERR_DH_FWK_PARA_INVALID; } int32_t ret = GetVersionFromVerMgr(uuid, dhType, version, isSink); @@ -861,7 +861,7 @@ int32_t ComponentManager::GetVersion(const std::string &uuid, DHType dhType, std void ComponentManager::UpdateVersionCache(const std::string &uuid, const VersionInfo &versionInfo) { - if (IdLengthInvalid(uuid)){ + if (IdLengthInvalid(uuid)) { return; } DHVersion dhVersion; @@ -950,7 +950,7 @@ std::map ComponentManager::GetDHSinkInstance( bool ComponentManager::IsIdenticalAccount(const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return false; } DmAuthForm authForm = DmAuthForm::INVALID_TYPE; @@ -974,7 +974,7 @@ bool ComponentManager::IsIdenticalAccount(const std::string &networkId) void ComponentManager::UpdateBusinessState(const std::string &networkId, const std::string &dhId, BusinessState state) { - if (IdLengthInvalid(networkId,dhId)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(dhId)) { return; } DHLOGI("UpdateBusinessState, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, @@ -998,7 +998,7 @@ void ComponentManager::UpdateBusinessState(const std::string &networkId, const s BusinessState ComponentManager::QueryBusinessState(const std::string &uuid, const std::string &dhId) { - if (IdLengthInvalid(uuid,dhId)){ + if (IdLengthInvalid(uuid,dhId)) { return BusinessState::UNKNOWN; } std::lock_guard lock(bizStateMtx_); @@ -1012,7 +1012,7 @@ BusinessState ComponentManager::QueryBusinessState(const std::string &uuid, cons void ComponentManager::TriggerFullCapsSync(const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return; } dhCommToolPtr_->TriggerReqFullDHCaps(networkId); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp index 1220cc26..27df7a5e 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp @@ -49,7 +49,7 @@ ComponentMonitor::~ComponentMonitor() void ComponentMonitor::CompSystemAbilityListener::OnAddSystemAbility(int32_t saId, const std::string &deviceId) { - if (IdLengthInvalid(deviceId)){ + if (IdLengthInvalid(deviceId)) { return; } DHLOGI("OnAddSystemAbility, saId: %{public}d, deviceId: %{public}s", saId, GetAnonyString(deviceId).c_str()); @@ -57,7 +57,7 @@ void ComponentMonitor::CompSystemAbilityListener::OnAddSystemAbility(int32_t saI void ComponentMonitor::CompSystemAbilityListener::OnRemoveSystemAbility(int32_t saId, const std::string &deviceId) { - if (IdLengthInvalid(deviceId)){ + if (IdLengthInvalid(deviceId)) { return; } DHLOGI("OnRemoveSystemAbility, saId: %{public}d, deviceId: %{public}s", saId, GetAnonyString(deviceId).c_str()); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp index 51c88716..391ff4a3 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_privacy.cpp @@ -47,7 +47,7 @@ ComponentPrivacy::~ComponentPrivacy() int32_t ComponentPrivacy::OnPrivaceResourceMessage(const ResourceEventType &type, const std::string &subtype, const std::string &networkId, bool &isSensitive, bool &isSameAccout) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("OnPrivaceResourceMessage start."); @@ -64,7 +64,7 @@ int32_t ComponentPrivacy::OnPrivaceResourceMessage(const ResourceEventType &type void ComponentPrivacy::HandlePullUpPage(const std::string &subtype, const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return; } cJSON *jsonArrayMsg = cJSON_CreateArray(); @@ -125,7 +125,7 @@ void ComponentPrivacy::HandleClosePage(const std::string &subtype) int32_t ComponentPrivacy::OnResourceInfoCallback(const std::string &subtype, const std::string &networkId, bool &isSensitive, bool &isSameAccout) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("OnResourceInfoCallback start."); @@ -158,7 +158,7 @@ int32_t ComponentPrivacy::OnResourceInfoCallback(const std::string &subtype, con int32_t ComponentPrivacy::StartPrivacePage(const std::string &subtype, const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("StartPrivacePage start."); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp b/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp index 11daa72a..3e3cd915 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp @@ -40,7 +40,7 @@ DHDataSyncTriggerListener::~DHDataSyncTriggerListener() void DHDataSyncTriggerListener::OnDataSyncTrigger(const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return; } DHLOGI("Receive data sync trigger, networkId: %{public}s", GetAnonyString(networkId).c_str()); diff --git a/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp b/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp index cff438a4..e08dbea9 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp @@ -39,7 +39,7 @@ DHStateListener::~DHStateListener() void DHStateListener::OnStateChanged(const std::string &networkId, const std::string &dhId, const BusinessState state) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return; } DHLOGI("Receive business state change, networkId: %{public}s, dhId: %{public}s, state: %{public}" PRIu32, diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp index c3db4a41..04cc67d1 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager.cpp @@ -97,7 +97,7 @@ int32_t DistributedHardwareManager::Release() int32_t DistributedHardwareManager::SendOnLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType) { - if (IdLengthInvalid(networkId,uuid,udid)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(uuid) || IdLengthInvalid(udid)) { return ERR_DH_FWK_PARA_INVALID; } (void)deviceType; @@ -119,7 +119,7 @@ int32_t DistributedHardwareManager::SendOnLineEvent(const std::string &networkId int32_t DistributedHardwareManager::SendOffLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType) { - if (IdLengthInvalid(networkId,uuid,udid)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(uuid) || IdLengthInvalid(udid)) { return ERR_DH_FWK_PARA_INVALID; } (void)deviceType; diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp index 6ed0f39f..f8fa5d1b 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_manager_factory.cpp @@ -148,7 +148,7 @@ bool DistributedHardwareManagerFactory::IsInit() int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType) { - if (IdLengthInvalid(networkId,uuid,udid)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(uuid) || IdLengthInvalid(udid)) { return ERR_DH_FWK_PARA_INVALID; } int32_t ret = pthread_setname_np(pthread_self(), SEND_ONLINE); @@ -179,7 +179,7 @@ int32_t DistributedHardwareManagerFactory::SendOnLineEvent(const std::string &ne int32_t DistributedHardwareManagerFactory::SendOffLineEvent(const std::string &networkId, const std::string &uuid, const std::string &udid, uint16_t deviceType) { - if (IdLengthInvalid(networkId,uuid,udid)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(uuid) || IdLengthInvalid(udid)) { return ERR_DH_FWK_PARA_INVALID; } if (!isInit && !Init()) { diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index 732746f9..e70b7b6a 100644 --- a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp +++ b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp @@ -306,7 +306,7 @@ int DistributedHardwareService::Dump(int32_t fd, const std::vector sinkMap = ComponentManager::GetInstance().GetDHSinkInstance(); @@ -324,7 +324,7 @@ int32_t DistributedHardwareService::PauseDistributedHardware(DHType dhType, cons int32_t DistributedHardwareService::ResumeDistributedHardware(DHType dhType, const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } std::map sinkMap = ComponentManager::GetInstance().GetDHSinkInstance(); @@ -342,7 +342,7 @@ int32_t DistributedHardwareService::ResumeDistributedHardware(DHType dhType, con int32_t DistributedHardwareService::StopDistributedHardware(DHType dhType, const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ERR_DH_FWK_PARA_INVALID; } std::map sinkMap = ComponentManager::GetInstance().GetDHSinkInstance(); diff --git a/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp b/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp index 47f14c25..cecdcb6f 100644 --- a/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp +++ b/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp @@ -22,7 +22,7 @@ IMPLEMENT_SINGLE_INSTANCE(EnabledCompsDump); void EnabledCompsDump::DumpEnabledComp(const std::string &networkId, const DHType dhType, const std::string &dhId) { - if (IdLengthInvalid(networkId,dhId)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(dhId)) { return; } HidumpCompInfo info(networkId, dhType, dhId); @@ -33,7 +33,7 @@ void EnabledCompsDump::DumpEnabledComp(const std::string &networkId, const DHTyp void EnabledCompsDump::DumpDisabledComp(const std::string &networkId, const DHType dhType, const std::string &dhId) { - if (IdLengthInvalid(networkId,dhId)){ + if (IdLengthInvalid(networkId) || IdLengthInvalid(dhId)) { return; } HidumpCompInfo info(networkId, dhType, dhId); diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp index 6ea9c0a8..2652175f 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp @@ -196,7 +196,7 @@ void LocalHardwareManager::CheckNonExistCapabilityInfo(const std::vector void LocalHardwareManager::GetLocalCapabilityMapByPrefix(const DHType dhType, CapabilityInfoMap &capabilityInfoMap) { std::string localDeviceId = DHContext::GetInstance().GetDeviceInfo().deviceId; - if (IdLengthInvalid(localDeviceId)){ + if (IdLengthInvalid(localDeviceId)) { return; } if (DHTypePrefixMap.find(dhType) == DHTypePrefixMap.end()) { diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp index cd2930e9..b5e030d3 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp @@ -55,7 +55,7 @@ void PluginListenerImpl::PluginHardware(const std::string &dhId, const std::stri void PluginListenerImpl::UnPluginHardware(const std::string &dhId) { - if (IdLengthInvalid(dhId)){ + if (IdLengthInvalid(dhId)) { return; } DHLOGI("unplugin start, dhId: %{public}s", GetAnonyString(dhId).c_str()); diff --git a/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp b/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp index 6119ab72..70216b6d 100644 --- a/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp +++ b/services/distributedhardwarefwkservice/src/lowlatency/low_latency_listener.cpp @@ -45,7 +45,7 @@ void LowLatencyListener::OnMessage(const DHTopic topic, const std::string& messa DHLOGE("Topic is invalid, topic: %{public}" PRIu32, (uint32_t)topic); return; } - if (MessageLengthInvalid(message)){ + if (MessageLengthInvalid(message)) { return; } cJSON *jsonObj = cJSON_Parse(message.c_str()); diff --git a/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp b/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp index 8218697d..77abd425 100644 --- a/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp +++ b/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp @@ -65,7 +65,7 @@ void PublisherItem::RemoveListener(const sptr &listener) void PublisherItem::PublishMessage(const std::string &message) { - if (MessageLengthInvalid(message)){ + if (MessageLengthInvalid(message)) { return; } std::lock_guard lock(mutex_); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info.cpp index bd2f3067..7401a664 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info.cpp @@ -120,7 +120,7 @@ std::string CapabilityInfo::GetAnonymousKey() const int32_t CapabilityInfo::FromJsonString(const std::string &jsonStr) { - if (JsonLengthInvalid(jsonStr)){ + if (JsonLengthInvalid(jsonStr)) { return ERR_DH_FWK_PARA_INVALID; } cJSON *jsonObj = cJSON_Parse(jsonStr.c_str()); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp index 3d3660b5..89c2ff9e 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp @@ -119,7 +119,7 @@ int32_t CapabilityInfoManager::UnInit() int32_t CapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &deviceId) { - if (IdLengthInvalid(deviceId)){ + if (IdLengthInvalid(deviceId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Sync DeviceInfo from DB, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); @@ -133,7 +133,7 @@ int32_t CapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &deviceId) DHLOGE("Query data from DB by deviceId failed, id: %{public}s", GetAnonyString(deviceId).c_str()); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (RecordSizeInvalid(dataVector)){ + if (RecordSizeInvalid(dataVector)) { return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -160,7 +160,7 @@ int32_t CapabilityInfoManager::SyncRemoteCapabilityInfos() DHLOGE("Query all data from DB failed"); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (RecordSizeInvalid(dataVector)){ + if (RecordSizeInvalid(dataVector)) { return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -186,7 +186,7 @@ int32_t CapabilityInfoManager::SyncRemoteCapabilityInfos() int32_t CapabilityInfoManager::AddCapability(const std::vector> &resInfos) { - if (RecordSizeInvalid(resInfos)){ + if (RecordSizeInvalid(resInfos)) { return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -226,7 +226,7 @@ int32_t CapabilityInfoManager::AddCapability(const std::vector> &resInfos) { - if (RecordSizeInvalid(resInfos)){ + if (RecordSizeInvalid(resInfos)) { return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -243,7 +243,7 @@ int32_t CapabilityInfoManager::AddCapabilityInMem(const std::vector &insertRecords) { - if (RecordSizeInvalid(insertRecords)){ + if (RecordSizeInvalid(insertRecords)) { return; } std::lock_guard lock(capInfoMgrMutex_); @@ -414,7 +414,7 @@ void CapabilityInfoManager::HandleCapabilityAddChange(const std::vector &updateRecords) { - if (RecordSizeInvalid(updateRecords)){ + if (RecordSizeInvalid(updateRecords)) { return; } std::lock_guard lock(capInfoMgrMutex_); @@ -433,7 +433,7 @@ void CapabilityInfoManager::HandleCapabilityUpdateChange(const std::vector &deleteRecords) { - if (RecordSizeInvalid(deleteRecords)){ + if (RecordSizeInvalid(deleteRecords)) { return; } std::lock_guard lock(capInfoMgrMutex_); @@ -475,7 +475,7 @@ bool CapabilityInfoManager::IsCapabilityMatchFilter(const std::shared_ptr> &resInfos) { - if (IdLengthInvalid(deviceId) || RecordSizeInvalid(resInfos)){ + if (IdLengthInvalid(deviceId) || RecordSizeInvalid(resInfos)) { return; } std::lock_guard lock(capInfoMgrMutex_); @@ -531,7 +531,7 @@ void CapabilityInfoManager::GetCapabilitiesByDeviceId(const std::string &deviceI bool CapabilityInfoManager::HasCapability(const std::string &deviceId, const std::string &dhId) { - if (IdLengthInvalid(deviceId,dhId)){ + if (IdLengthInvalid(deviceId) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -545,7 +545,7 @@ bool CapabilityInfoManager::HasCapability(const std::string &deviceId, const std int32_t CapabilityInfoManager::GetCapability(const std::string &deviceId, const std::string &dhId, std::shared_ptr &capPtr) { - if (IdLengthInvalid(deviceId,dhId)){ + if (IdLengthInvalid(deviceId) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -560,7 +560,7 @@ int32_t CapabilityInfoManager::GetCapability(const std::string &deviceId, const int32_t CapabilityInfoManager::GetDataByKey(const std::string &key, std::shared_ptr &capInfoPtr) { - if (IdLengthInvalid(key)){ + if (IdLengthInvalid(key)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -590,7 +590,7 @@ int32_t CapabilityInfoManager::GetDataByDHType(const DHType dhType, CapabilityIn int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, CapabilityInfoMap &capabilityMap) { - if (IdLengthInvalid(keyPrefix)){ + if (IdLengthInvalid(keyPrefix)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -603,7 +603,7 @@ int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, DHLOGE("Query capability info from db failed, key: %{public}s", GetAnonyString(keyPrefix).c_str()); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (RecordSizeInvalid(dataVector)){ + if (RecordSizeInvalid(dataVector)) { return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -627,7 +627,7 @@ void CapabilityInfoManager::DumpCapabilityInfos(std::vector &cap std::vector CapabilityInfoManager::GetEntriesByKeys(const std::vector &keys) { - if (ArrayLengthInvalid(keys)){ + if (ArrayLengthInvalid(keys)) { return {}; } DHLOGI("call"); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp index 96a1c6a2..922400d3 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp @@ -32,7 +32,7 @@ std::string GetCapabilityKey(const std::string &deviceId, const std::string &dhI bool IsCapKeyMatchDeviceId(const std::string &key, const std::string &deviceId) { - if (IdLengthInvalid(key,deviceId)){ + if (IdLengthInvalid(key) || IdLengthInvalid(deviceId)) { return false; } std::size_t separatorPos = key.find(RESOURCE_SEPARATOR); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp index d971aacf..d908a93f 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp @@ -191,7 +191,7 @@ int32_t DBAdapter::ReInit(bool isAutoSync) std::string DBAdapter::GetNetworkIdByKey(const std::string &key) { - if (IdLengthInvalid(key)){ + if (IdLengthInvalid(key)) { return ""; } DHLOGI("Get networkId by key: %{public}s", GetAnonyString(key).c_str()); @@ -221,7 +221,7 @@ std::string DBAdapter::GetNetworkIdByKey(const std::string &key) void DBAdapter::SyncByNotFound(const std::string &key) { - if (IdLengthInvalid(key)){ + if (IdLengthInvalid(key)) { return; } std::string networkId = GetNetworkIdByKey(key); @@ -239,7 +239,7 @@ void DBAdapter::SyncByNotFound(const std::string &key) int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) { - if (IdLengthInvalid(key) || MessageLengthInvalid(data)){ + if (IdLengthInvalid(key) || MessageLengthInvalid(data)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Get data by key: %{public}s, storeId: %{public}s, dataType: %{public}d", @@ -272,7 +272,7 @@ int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector &values) { - if (IdLengthInvalid(keyPrefix)){ + if (IdLengthInvalid(keyPrefix)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Get data by key prefix: %{public}s, storeId: %{public}s, dataType: %{public}d", @@ -301,7 +301,7 @@ int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector< GetAnonyString(keyPrefix).c_str()); return ERR_DH_FWK_RESOURCE_KV_STORAGE_OPERATION_FAIL; } - if (RecordSizeInvalid(allEntries)){ + if (RecordSizeInvalid(allEntries)) { return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto& item : allEntries) { @@ -312,7 +312,7 @@ int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector< int32_t DBAdapter::PutData(const std::string &key, const std::string &value) { - if (IdLengthInvalid(key) || MessageLengthInvalid(value)){ + if (IdLengthInvalid(key) || MessageLengthInvalid(value)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(dbAdapterMutex_); @@ -332,7 +332,7 @@ int32_t DBAdapter::PutData(const std::string &key, const std::string &value) int32_t DBAdapter::PutDataBatch(const std::vector &keys, const std::vector &values) { - if (ArrayLengthInvalid(keys) || ArrayLengthInvalid(values)){ + if (ArrayLengthInvalid(keys) || ArrayLengthInvalid(values)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(dbAdapterMutex_); @@ -485,7 +485,7 @@ void DBAdapter::DeleteKvStore() int32_t DBAdapter::RemoveDeviceData(const std::string &deviceId) { - if (IdLengthInvalid(deviceId)){ + if (IdLengthInvalid(deviceId)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(dbAdapterMutex_); @@ -504,7 +504,7 @@ int32_t DBAdapter::RemoveDeviceData(const std::string &deviceId) int32_t DBAdapter::RemoveDataByKey(const std::string &key) { - if (IdLengthInvalid(key)){ + if (IdLengthInvalid(key)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(dbAdapterMutex_); @@ -524,7 +524,7 @@ int32_t DBAdapter::RemoveDataByKey(const std::string &key) std::vector DBAdapter::GetEntriesByKeys(const std::vector &keys) { - if (ArrayLengthInvalid(keys)){ + if (ArrayLengthInvalid(keys)) { return {}; } DHLOGI("call"); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp index 828b08bb..6bb97e34 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/local_capability_info_manager.cpp @@ -83,7 +83,7 @@ int32_t LocalCapabilityInfoManager::UnInit() int32_t LocalCapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &deviceId) { - if (IdLengthInvalid(deviceId)){ + if (IdLengthInvalid(deviceId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Sync DeviceInfo from DB, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); @@ -97,7 +97,7 @@ int32_t LocalCapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &devi DHLOGE("Query data from DB by deviceId failed, id: %{public}s", GetAnonyString(deviceId).c_str()); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (RecordSizeInvalid(dataVector)){ + if (RecordSizeInvalid(dataVector)) { return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -113,7 +113,7 @@ int32_t LocalCapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &devi int32_t LocalCapabilityInfoManager::AddCapability(const std::vector> &resInfos) { - if (RecordSizeInvalid(resInfos)){ + if (RecordSizeInvalid(resInfos)) { return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -147,7 +147,7 @@ int32_t LocalCapabilityInfoManager::AddCapability(const std::vector> &resInfos) { - if (IdLengthInvalid(deviceId) || RecordSizeInvalid(resInfos)){ + if (IdLengthInvalid(deviceId) || RecordSizeInvalid(resInfos)) { return; } std::lock_guard lock(capInfoMgrMutex_); @@ -184,7 +184,7 @@ void LocalCapabilityInfoManager::GetCapabilitiesByDeviceId(const std::string &de int32_t LocalCapabilityInfoManager::GetCapability(const std::string &deviceId, const std::string &dhId, std::shared_ptr &capPtr) { - if (IdLengthInvalid(deviceId,dhId)){ + if (IdLengthInvalid(deviceId) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -199,7 +199,7 @@ int32_t LocalCapabilityInfoManager::GetCapability(const std::string &deviceId, c int32_t LocalCapabilityInfoManager::GetDataByKey(const std::string &key, std::shared_ptr &capInfoPtr) { - if (IdLengthInvalid(key)){ + if (IdLengthInvalid(key)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -229,7 +229,7 @@ int32_t LocalCapabilityInfoManager::GetDataByDHType(const DHType dhType, Capabil int32_t LocalCapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, CapabilityInfoMap &capabilityMap) { - if (KeySizeInvalid(keyPrefix)){ + if (KeySizeInvalid(keyPrefix)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -242,7 +242,7 @@ int32_t LocalCapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPre DHLOGE("Query capability info from db failed, key: %{public}s", GetAnonyString(keyPrefix).c_str()); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (RecordSizeInvalid(dataVector)){ + if (RecordSizeInvalid(dataVector)) { return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp index f9ee6392..2f9162da 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp @@ -52,7 +52,7 @@ void MetaCapabilityInfo::SetSinkVersion(const std::string &sinkVersion) int32_t MetaCapabilityInfo::FromJsonString(const std::string &jsonStr) { - if (JsonLengthInvalid(jsonStr)){ + if (JsonLengthInvalid(jsonStr)) { return ERR_DH_FWK_PARA_INVALID; } cJSON *jsonObj = cJSON_Parse(jsonStr.c_str()); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp index 0aed4a5f..5c2c5ead 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp @@ -116,7 +116,7 @@ int32_t MetaInfoManager::UnInit() int32_t MetaInfoManager::AddMetaCapInfos(const std::vector> &metaCapInfos) { - if (RecordSizeInvalid(metaCapInfos)){ + if (RecordSizeInvalid(metaCapInfos)) { return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } std::lock_guard lock(metaInfoMgrMutex_); @@ -155,7 +155,7 @@ int32_t MetaInfoManager::AddMetaCapInfos(const std::vector lock(metaInfoMgrMutex_); @@ -237,7 +237,7 @@ int32_t MetaInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, MetaCa DHLOGE("Query metaInfo from db failed, keyPrefix: %{public}s", GetAnonyString(keyPrefix).c_str()); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (RecordSizeInvalid(dataVector)){ + if (RecordSizeInvalid(dataVector)) { return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -253,7 +253,7 @@ int32_t MetaInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, MetaCa int32_t MetaInfoManager::RemoveMetaInfoByKey(const std::string &key) { - if (KeySizeInvalid(key)){ + if (KeySizeInvalid(key)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Remove device metaInfo, key: %{public}s", GetAnonyString(key).c_str()); @@ -274,7 +274,7 @@ int32_t MetaInfoManager::RemoveMetaInfoByKey(const std::string &key) int32_t MetaInfoManager::GetMetaCapInfo(const std::string &udidHash, const std::string &dhId, std::shared_ptr &metaCapPtr) { - if (HashSizeInvalid(udidHash) || IdLengthInvalid(dhId)){ + if (HashSizeInvalid(udidHash) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(metaInfoMgrMutex_); @@ -290,7 +290,7 @@ int32_t MetaInfoManager::GetMetaCapInfo(const std::string &udidHash, void MetaInfoManager::GetMetaCapInfosByUdidHash(const std::string &udidHash, std::vector> &metaCapInfos) { - if (HashSizeInvalid(udidHash)){ + if (HashSizeInvalid(udidHash)) { return; } std::lock_guard lock(metaInfoMgrMutex_); @@ -303,7 +303,7 @@ void MetaInfoManager::GetMetaCapInfosByUdidHash(const std::string &udidHash, int32_t MetaInfoManager::GetMetaCapByValue(const std::string &value, std::shared_ptr &metaCapPtr) { - if (MessageLengthInvalid(value)){ + if (MessageLengthInvalid(value)) { return ERR_DH_FWK_PARA_INVALID; } if (metaCapPtr == nullptr) { @@ -361,7 +361,7 @@ void MetaInfoManager::OnChange(const DistributedKv::DataOrigin &origin, Keys &&k void MetaInfoManager::HandleMetaCapabilityAddChange(const std::vector &insertRecords) { - if (RecordSizeInvalid(insertRecords)){ + if (RecordSizeInvalid(insertRecords)) { return; } std::lock_guard lock(metaInfoMgrMutex_); @@ -398,7 +398,7 @@ void MetaInfoManager::HandleMetaCapabilityAddChange(const std::vector &updateRecords) { - if (RecordSizeInvalid(updateRecords)){ + if (RecordSizeInvalid(updateRecords)) { return; } std::lock_guard lock(metaInfoMgrMutex_); @@ -417,7 +417,7 @@ void MetaInfoManager::HandleMetaCapabilityUpdateChange(const std::vector &deleteRecords) { - if (RecordSizeInvalid(deleteRecords)){ + if (RecordSizeInvalid(deleteRecords)) { return; } std::lock_guard lock(metaInfoMgrMutex_); @@ -436,7 +436,7 @@ void MetaInfoManager::HandleMetaCapabilityDeleteChange(const std::vector MetaInfoManager::GetEntriesByKeys(const std::vector &keys) { - if (ArrayLengthInvalid(keys)){ + if (ArrayLengthInvalid(keys)) { return {}; } DHLOGI("call"); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp index e6b08acd..10bd5654 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/version_info.cpp @@ -32,7 +32,7 @@ namespace DistributedHardware { int32_t VersionInfo::FromJsonString(const std::string &jsonStr) { - if (JsonLengthInvalid(jsonStr)){ + if (JsonLengthInvalid(jsonStr)) { return ERR_DH_FWK_PARA_INVALID; } cJSON *jsonObj = cJSON_Parse(jsonStr.c_str()); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp index 61ff6802..a9efa807 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp @@ -138,7 +138,7 @@ int32_t VersionInfoManager::AddVersion(const VersionInfo &versionInfo) int32_t VersionInfoManager::GetVersionInfoByDeviceId(const std::string &deviceId, VersionInfo &versionInfo) { - if (IdLengthInvalid(deviceId)){ + if (IdLengthInvalid(deviceId)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(verInfoMgrMutex_); @@ -170,7 +170,7 @@ void VersionInfoManager::UpdateVersionCache(const VersionInfo &versionInfo) int32_t VersionInfoManager::RemoveVersionInfoByDeviceId(const std::string &deviceId) { - if (IdLengthInvalid(deviceId)){ + if (IdLengthInvalid(deviceId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Remove version device info, key: %{public}s", GetAnonyString(deviceId).c_str()); @@ -198,7 +198,7 @@ int32_t VersionInfoManager::RemoveVersionInfoByDeviceId(const std::string &devic int32_t VersionInfoManager::SyncVersionInfoFromDB(const std::string &deviceId) { - if (IdLengthInvalid(deviceId)){ + if (IdLengthInvalid(deviceId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Sync versionInfo from DB, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); @@ -236,7 +236,7 @@ int32_t VersionInfoManager::SyncRemoteVersionInfos() DHLOGE("Query all data from DB failed"); return ERR_DH_FWK_RESOURCE_DB_ADAPTER_OPERATION_FAIL; } - if (RecordSizeInvalid(dataVector)){ + if (RecordSizeInvalid(dataVector)) { return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -282,7 +282,7 @@ void VersionInfoManager::OnChange(const DistributedKv::ChangeNotification &chang void VersionInfoManager::HandleVersionAddChange(const std::vector &insertRecords) { - if (RecordSizeInvalid(insertRecords)){ + if (RecordSizeInvalid(insertRecords)) { return; } DHLOGI("Version add change"); @@ -298,7 +298,7 @@ void VersionInfoManager::HandleVersionAddChange(const std::vector &updateRecords) { - if (RecordSizeInvalid(updateRecords)){ + if (RecordSizeInvalid(updateRecords)) { return; } DHLOGI("Version update change"); @@ -314,7 +314,7 @@ void VersionInfoManager::HandleVersionUpdateChange(const std::vector &deleteRecords) { - if (RecordSizeInvalid(deleteRecords)){ + if (RecordSizeInvalid(deleteRecords)) { return; } DHLOGI("Version delete change"); diff --git a/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp b/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp index 51014589..7619fe75 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp @@ -108,7 +108,7 @@ void DHTransport::OnBytesReceived(int32_t socketId, const void *data, uint32_t d void DHTransport::HandleReceiveMessage(const std::string &payload) { - if (MessageLengthInvalid(payload)){ + if (MessageLengthInvalid(payload)) { return; } std::string rawPayload = Decompress(payload); @@ -248,7 +248,7 @@ int32_t DHTransport::CreateServerSocket() int32_t DHTransport::CreateClientSocket(const std::string &remoteNetworkId) { - if (IdLengthInvalid(remoteNetworkId)){ + if (IdLengthInvalid(remoteNetworkId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("CreateClientSocket start, peerNetworkId: %{public}s", GetAnonyString(remoteNetworkId).c_str()); @@ -315,7 +315,7 @@ int32_t DHTransport::UnInit() bool DHTransport::IsDeviceSessionOpened(const std::string &remoteNetworkId, int32_t &socketId) { - if (IdLengthInvalid(remoteNetworkId)){ + if (IdLengthInvalid(remoteNetworkId)) { return false; } std::lock_guard lock(rmtSocketIdMtx_); @@ -343,7 +343,7 @@ std::string DHTransport::GetRemoteNetworkIdBySocketId(int32_t socketId) void DHTransport::ClearDeviceSocketOpened(const std::string &remoteDevId) { - if (IdLengthInvalid(remoteDevId)){ + if (IdLengthInvalid(remoteDevId)) { return; } std::lock_guard lock(rmtSocketIdMtx_); @@ -352,7 +352,7 @@ void DHTransport::ClearDeviceSocketOpened(const std::string &remoteDevId) int32_t DHTransport::StartSocket(const std::string &remoteNetworkId) { - if (IdLengthInvalid(remoteNetworkId)){ + if (IdLengthInvalid(remoteNetworkId)) { return ERR_DH_FWK_PARA_INVALID; } int32_t socketId = -1; @@ -390,7 +390,7 @@ int32_t DHTransport::StartSocket(const std::string &remoteNetworkId) int32_t DHTransport::StopSocket(const std::string &remoteNetworkId) { - if (IdLengthInvalid(remoteNetworkId)){ + if (IdLengthInvalid(remoteNetworkId)) { return ERR_DH_FWK_PARA_INVALID; } int32_t socketId = -1; @@ -408,7 +408,7 @@ int32_t DHTransport::StopSocket(const std::string &remoteNetworkId) int32_t DHTransport::Send(const std::string &remoteNetworkId, const std::string &payload) { - if (IdLengthInvalid(remoteNetworkId) || MessageLengthInvalid(payload)){ + if (IdLengthInvalid(remoteNetworkId) || MessageLengthInvalid(payload)) { return ERR_DH_FWK_PARA_INVALID; } int32_t socketId = -1; diff --git a/services/distributedhardwarefwkservice/src/utils/dh_context.cpp b/services/distributedhardwarefwkservice/src/utils/dh_context.cpp index 25df6743..879b5dd3 100644 --- a/services/distributedhardwarefwkservice/src/utils/dh_context.cpp +++ b/services/distributedhardwarefwkservice/src/utils/dh_context.cpp @@ -114,7 +114,7 @@ const DeviceInfo& DHContext::GetDeviceInfo() void DHContext::AddOnlineDevice(const std::string &udid, const std::string &uuid, const std::string &networkId) { - if (IdLengthInvalid(udid,uuid,networkId)){ + if (IdLengthInvalid(udid) || IdLengthInvalid(uuid) || IdLengthInvalid(networkId)) { return; } std::unique_lock lock(onlineDevMutex_); @@ -136,7 +136,7 @@ void DHContext::AddOnlineDevice(const std::string &udid, const std::string &uuid void DHContext::RemoveOnlineDeviceByUUID(const std::string &uuid) { - if (IdLengthInvalid(uuid)){ + if (IdLengthInvalid(uuid)) { return; } std::unique_lock lock(onlineDevMutex_); @@ -172,7 +172,7 @@ size_t DHContext::GetOnlineCount() std::string DHContext::GetNetworkIdByUUID(const std::string &uuid) { - if (IdLengthInvalid(uuid)){ + if (IdLengthInvalid(uuid)) { return ""; } std::unique_lock lock(onlineDevMutex_); @@ -188,7 +188,7 @@ std::string DHContext::GetNetworkIdByUUID(const std::string &uuid) std::string DHContext::GetUdidHashIdByUUID(const std::string &uuid) { - if ( IdLengthInvalid(uuid)){ + if ( IdLengthInvalid(uuid)) { return ""; } std::unique_lock lock(onlineDevMutex_); @@ -204,7 +204,7 @@ std::string DHContext::GetUdidHashIdByUUID(const std::string &uuid) std::string DHContext::GetUUIDByNetworkId(const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ""; } std::unique_lock lock(onlineDevMutex_); @@ -220,7 +220,7 @@ std::string DHContext::GetUUIDByNetworkId(const std::string &networkId) std::string DHContext::GetUDIDByNetworkId(const std::string &networkId) { - if (IdLengthInvalid(networkId)){ + if (IdLengthInvalid(networkId)) { return ""; } std::unique_lock lock(onlineDevMutex_); @@ -236,7 +236,7 @@ std::string DHContext::GetUDIDByNetworkId(const std::string &networkId) std::string DHContext::GetUUIDByDeviceId(const std::string &deviceId) { - if (IdLengthInvalid(deviceId)){ + if (IdLengthInvalid(deviceId)) { return ""; } std::unique_lock lock(onlineDevMutex_); @@ -252,7 +252,7 @@ std::string DHContext::GetUUIDByDeviceId(const std::string &deviceId) std::string DHContext::GetNetworkIdByDeviceId(const std::string &deviceId) { - if (IdLengthInvalid(deviceId)){ + if (IdLengthInvalid(deviceId)) { return ""; } std::unique_lock lock(onlineDevMutex_); @@ -268,7 +268,7 @@ std::string DHContext::GetNetworkIdByDeviceId(const std::string &deviceId) std::string DHContext::GetDeviceIdByDBGetPrefix(const std::string &prefix) { - if (IdLengthInvalid(prefix)){ + if (IdLengthInvalid(prefix)) { return ""; } std::string id = ""; @@ -297,7 +297,7 @@ void DHContext::RegisDHFWKIsomerismListener() void DHContext::DHFWKIsomerismListener::OnMessage(const DHTopic topic, const std::string &message) { - if (MessageLengthInvalid(message)){ + if (MessageLengthInvalid(message)) { return; } DHLOGI("OnMessage topic: %{public}u", static_cast(topic)); @@ -335,7 +335,7 @@ void DHContext::DHFWKIsomerismListener::OnMessage(const DHTopic topic, const std void DHContext::AddIsomerismConnectDev(const std::string &IsomerismDeviceId) { - if (IdLengthInvalid(IsomerismDeviceId)){ + if (IdLengthInvalid(IsomerismDeviceId)) { return; } DHLOGI("AddIsomerismConnectDev id = %{public}s", GetAnonyString(IsomerismDeviceId).c_str()); @@ -345,7 +345,7 @@ void DHContext::AddIsomerismConnectDev(const std::string &IsomerismDeviceId) void DHContext::DelIsomerismConnectDev(const std::string &IsomerismDeviceId) { - if (IdLengthInvalid(IsomerismDeviceId)){ + if (IdLengthInvalid(IsomerismDeviceId)) { return; } DHLOGI("DelIsomerismConnectDev id = %{public}s", GetAnonyString(IsomerismDeviceId).c_str()); diff --git a/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp b/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp index 38d6b52f..aeb74beb 100644 --- a/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp +++ b/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp @@ -61,7 +61,7 @@ void VersionManager::ShowLocalVersion(const DHVersion &dhVersion) const int32_t VersionManager::AddDHVersion(const std::string &uuid, const DHVersion &dhVersion) { - if (IdLengthInvalid(uuid)){ + if (IdLengthInvalid(uuid)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("addDHVersion uuid: %{public}s", GetAnonyString(uuid).c_str()); @@ -72,7 +72,7 @@ int32_t VersionManager::AddDHVersion(const std::string &uuid, const DHVersion &d int32_t VersionManager::RemoveDHVersion(const std::string &uuid) { - if (IdLengthInvalid(uuid)){ + if (IdLengthInvalid(uuid)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("uuid: %{public}s", GetAnonyString(uuid).c_str()); @@ -88,7 +88,7 @@ int32_t VersionManager::RemoveDHVersion(const std::string &uuid) int32_t VersionManager::GetDHVersion(const std::string &uuid, DHVersion &dhVersion) { - if (IdLengthInvalid(uuid)){ + if (IdLengthInvalid(uuid)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("uuid: %{public}s", GetAnonyString(uuid).c_str()); @@ -105,7 +105,7 @@ int32_t VersionManager::GetDHVersion(const std::string &uuid, DHVersion &dhVersi int32_t VersionManager::GetCompVersion(const std::string &uuid, const DHType dhType, CompVersion &compVersion) { - if (IdLengthInvalid(uuid)){ + if (IdLengthInvalid(uuid)) { return ERR_DH_FWK_PARA_INVALID; } DHVersion dhVersion; diff --git a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp index a00e2882..30a350c2 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/localhardwaremanager/pluginlistenerimpl/src/mock_hardware_handler.cpp @@ -61,7 +61,7 @@ void MockHardwareHandler::UnRegisterPluginListener() int32_t MockHardwareHandler::PluginHardware(const std::string &dhId, const std::string &attr, const std::string &subtype) { - if (IdLengthInvalid(dhId)){ + if (IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } if (listener_ != nullptr) { @@ -72,7 +72,7 @@ int32_t MockHardwareHandler::PluginHardware(const std::string &dhId, const std:: int32_t MockHardwareHandler::UnPluginHardware(const std::string &dhId) { - if (HashSizeInvalid(udidHash)){ + if (HashSizeInvalid(udidHash)) { return ERR_DH_FWK_PARA_INVALID; } if (listener_ != nullptr) { diff --git a/utils/include/dh_utils_tool.h b/utils/include/dh_utils_tool.h index aec852df..9b6eb126 100644 --- a/utils/include/dh_utils_tool.h +++ b/utils/include/dh_utils_tool.h @@ -66,8 +66,7 @@ std::string Decompress(const std::string& data); bool GetSysPara(const char *key, bool &value); -template -bool IdLengthInvalid(const Args &...args); +bool IdLengthInvalid(const std::string &input); bool MessageLengthInvalid(const std::string &input); diff --git a/utils/src/anonymous_string.cpp b/utils/src/anonymous_string.cpp index bcef3853..f91191af 100644 --- a/utils/src/anonymous_string.cpp +++ b/utils/src/anonymous_string.cpp @@ -34,7 +34,7 @@ namespace { } std::string GetAnonyString(const std::string &value) { - if (MessageLengthInvalid(value)){ + if (MessageLengthInvalid(value)) { return ""; } std::string res; diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index 40ce2d7e..0b977874 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -277,18 +277,15 @@ bool GetSysPara(const char *key, bool &value) return true; } -template -bool IdLengthInvalid(const Args &...args) +bool IdLengthInvalid(const std::string &input) { - std::vector flag{ args.empty()..., (args.length() > MAX_ID_LEN)... }; - - if (std::all_of(flag.begin(),flag.end(),[](bool i) {return !i; })) { - return false; - } - else { + if (input.empty() || input.length()) { DHLOGE("On parameter length error, maybe empty or beyond MAX_ID_LEN!"); return true; } + else { + return false; + } } bool MessageLengthInvalid(const std::string &input) @@ -296,7 +293,8 @@ bool MessageLengthInvalid(const std::string &input) if (input.empty() || input.length() > MAX_MESSAGE_LEN){ DHLOGE("On parameter error, maybe empty or beyond MAX_MESSAGE_LEN!"); return true; - }else{ + } + else { return false; } } @@ -307,7 +305,8 @@ bool RecordSizeInvalid(const std::vector &input) if (input.empty() || input.size() > MAX_DB_RECORD_SIZE){ DHLOGE("On parameter error, maybe empty or beyond MAX_DE_RECORD_SIZE!"); return true; - }else{ + } + else { return false; } } @@ -317,7 +316,8 @@ bool JsonLengthInvalid(const std::string &jsonStr) if (jsonStr.empty() || jsonStr.length() > MAX_JSON_SIZE){ DHLOGE("On parameter error, maybe empty or beyond MAX_JSON_SIZE"); return true; - }else{ + } + else { return false; } } @@ -328,7 +328,8 @@ bool ArrayLengthInvalid(const std::vector &array) if (array.empty() || array.size() > MAX_ARR_SIZE){ DHLOGE("On parameter error, maybe empty or beyond MAX_ARR_SIZE"); return true; - }else{ + } + else { return false; } } @@ -338,7 +339,8 @@ bool KeySizeInvalid(const std::string &key) if (key.empty() || key.length() > MAX_KEY_SIZE){ DHLOGE("On parameter error, maybe empty or beyond MAX_KEY_SIZE"); return true; - }else{ + } + else { return false; } } @@ -348,7 +350,8 @@ bool HashSizeInvalid(const std::string &hashValue) if (hashValue.empty() || hashValue.length() > MAX_HASH_SIZE){ DHLOGE("On parameter error, maybe empty or beyond MAX_HASH_SIZE"); return true; - }else{ + } + else { return false; } } -- Gitee From 6acebc071f05f94e36d6faad4032d539c74d816c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Thu, 18 Jul 2024 18:15:36 +0800 Subject: [PATCH 3/6] second altering a.t. AI MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- .../componentmanager/component_manager.cpp | 21 ++++++++----------- .../resourcemanager/meta_capability_info.cpp | 4 ---- .../src/transport/dh_transport.cpp | 2 +- .../src/utils/dh_context.cpp | 2 +- utils/src/dh_utils_tool.cpp | 16 +++++++------- 5 files changed, 19 insertions(+), 26 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 815ae4d1..f326c058 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -520,8 +520,7 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string return ERR_DH_FWK_PARA_INVALID; } DHLOGI("start."); - auto find = compSource_.find(dhType); - if (find == compSource_.end()) { + if (compSource_.find(dhType) == compSource_.end()) { DHLOGE("can not find handler for dhId = %{public}s.", GetAnonyString(dhId).c_str()); return ERR_DH_FWK_PARA_INVALID; } @@ -540,22 +539,20 @@ int32_t ComponentManager::Enable(const std::string &networkId, const std::string DHLOGE("GetCompResourceDesc failed, subtype: %{public}s", subtype.c_str()); return ERR_DH_FWK_RESOURCE_KEY_IS_EMPTY; } - bool sensitiveVal = resourceDesc[subtype]; - bool isSameAuthForm = IsIdenticalAccount(networkId); - if (sensitiveVal && !isSameAuthForm) { + if (resourceDesc[subtype] && !IsIdenticalAccount(networkId)) { DHLOGE("Privacy resources must be logged in with the same account."); return ERR_DH_FWK_COMPONENT_ENABLE_FAILED; } auto compEnable = std::make_shared(); - auto result = compEnable->Enable(networkId, dhId, param, find->second); + auto result = compEnable->Enable(networkId, dhId, param, (compSource_.find(dhType))->second); if (result != DH_FWK_SUCCESS) { for (int32_t retryCount = 0; retryCount < ENABLE_RETRY_MAX_TIMES; retryCount++) { if (!DHContext::GetInstance().IsDeviceOnline(uuid)) { DHLOGE("device is already offline, no need try enable, uuid= %{public}s", GetAnonyString(uuid).c_str()); return result; } - if (compEnable->Enable(networkId, dhId, param, find->second) == DH_FWK_SUCCESS) { + if (compEnable->Enable(networkId, dhId, param, (compSource_.find(dhType))->second) == DH_FWK_SUCCESS) { DHLOGE("enable success, retryCount = %{public}d", retryCount); EnabledCompsDump::GetInstance().DumpEnabledComp(networkId, dhType, dhId); return DH_FWK_SUCCESS; @@ -645,7 +642,7 @@ DHType ComponentManager::GetDHType(const std::string &uuid, const std::string &d int32_t ComponentManager::GetEnableCapParam(const std::string &networkId, const std::string &uuid, DHType dhType, EnableParam ¶m, std::shared_ptr &capability) { - if (IdLengthInvalid(networkId,uuid)) { + if (IdLengthInvalid(networkId) || IdLengthInvalid(uuid)) { return ERR_DH_FWK_PARA_INVALID; } DeviceInfo sourceDeviceInfo = GetLocalDeviceInfo(); @@ -694,7 +691,7 @@ int32_t ComponentManager::GetEnableCapParam(const std::string &networkId, const int32_t ComponentManager::GetEnableMetaParam(const std::string &networkId, const std::string &uuid, DHType dhType, EnableParam ¶m, std::shared_ptr &metaCapPtr) { - if (IdLengthInvalid(networkId,uuid)) { + if (IdLengthInvalid(networkId) || IdLengthInvalid(uuid)) { return ERR_DH_FWK_PARA_INVALID; } DeviceInfo sourceDeviceInfo = GetLocalDeviceInfo(); @@ -729,7 +726,7 @@ int32_t ComponentManager::GetEnableMetaParam(const std::string &networkId, const int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string &dhId, std::shared_ptr &capability) { - if (IdLengthInvalid(uuid,dhId)) { + if (IdLengthInvalid(uuid) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } std::string deviceId = GetDeviceIdByUUID(uuid); @@ -753,7 +750,7 @@ int32_t ComponentManager::GetCapParam(const std::string &uuid, const std::string int32_t ComponentManager::GetMetaParam(const std::string &uuid, const std::string &dhId, std::shared_ptr &metaCapPtr) { - if (IdLengthInvalid(uuid,dhId)) { + if (IdLengthInvalid(uuid) || IdLengthInvalid(dhId)) { return ERR_DH_FWK_PARA_INVALID; } auto ret = MetaInfoManager::GetInstance()->GetMetaCapInfo(DHContext::GetInstance().GetUdidHashIdByUUID(uuid), @@ -998,7 +995,7 @@ void ComponentManager::UpdateBusinessState(const std::string &networkId, const s BusinessState ComponentManager::QueryBusinessState(const std::string &uuid, const std::string &dhId) { - if (IdLengthInvalid(uuid,dhId)) { + if (IdLengthInvalid(uuid) || IdLengthInvalid(dhId)) { return BusinessState::UNKNOWN; } std::lock_guard lock(bizStateMtx_); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp index 2f9162da..d0648c18 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_capability_info.cpp @@ -163,10 +163,6 @@ void ToJson(cJSON *jsonObject, const MetaCapabilityInfo &metaCapInfo) void FromJson(const cJSON *jsonObject, MetaCapabilityInfo &metaCapInfo) { - if (jsonObject == nullptr) { - DHLOGE("Json pointer is nullptr!"); - return; - } if (!IsString(jsonObject, DH_ID)) { DHLOGE("DH_ID is invalid!"); return; diff --git a/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp b/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp index 7619fe75..078be884 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_transport.cpp @@ -208,7 +208,7 @@ void OnFile(int32_t socket, FileEvent *event) void OnQos(int32_t socket, QoSEvent eventId, const QosTV *qos, uint32_t qosCount) { - if (qosCount < 0 || qosCount > MAX_ROUND_SIZE){ + if (qosCount <= 0 || qosCount > MAX_ROUND_SIZE) { DHLOGE("qosCount is invalid!"); return; } diff --git a/services/distributedhardwarefwkservice/src/utils/dh_context.cpp b/services/distributedhardwarefwkservice/src/utils/dh_context.cpp index 879b5dd3..115f44be 100644 --- a/services/distributedhardwarefwkservice/src/utils/dh_context.cpp +++ b/services/distributedhardwarefwkservice/src/utils/dh_context.cpp @@ -188,7 +188,7 @@ std::string DHContext::GetNetworkIdByUUID(const std::string &uuid) std::string DHContext::GetUdidHashIdByUUID(const std::string &uuid) { - if ( IdLengthInvalid(uuid)) { + if (IdLengthInvalid(uuid)) { return ""; } std::unique_lock lock(onlineDevMutex_); diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index 0b977874..b6ba5185 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -277,9 +277,9 @@ bool GetSysPara(const char *key, bool &value) return true; } -bool IdLengthInvalid(const std::string &input) +bool IdLengthInvalid(const std::string & input) { - if (input.empty() || input.length()) { + if (input.empty() || input.length() > MAX_ID_LEN) { DHLOGE("On parameter length error, maybe empty or beyond MAX_ID_LEN!"); return true; } @@ -290,7 +290,7 @@ bool IdLengthInvalid(const std::string &input) bool MessageLengthInvalid(const std::string &input) { - if (input.empty() || input.length() > MAX_MESSAGE_LEN){ + if (input.empty() || input.length() > MAX_MESSAGE_LEN) { DHLOGE("On parameter error, maybe empty or beyond MAX_MESSAGE_LEN!"); return true; } @@ -302,7 +302,7 @@ bool MessageLengthInvalid(const std::string &input) template bool RecordSizeInvalid(const std::vector &input) { - if (input.empty() || input.size() > MAX_DB_RECORD_SIZE){ + if (input.empty() || input.size() > MAX_DB_RECORD_SIZE) { DHLOGE("On parameter error, maybe empty or beyond MAX_DE_RECORD_SIZE!"); return true; } @@ -313,7 +313,7 @@ bool RecordSizeInvalid(const std::vector &input) bool JsonLengthInvalid(const std::string &jsonStr) { - if (jsonStr.empty() || jsonStr.length() > MAX_JSON_SIZE){ + if (jsonStr.empty() || jsonStr.length() > MAX_JSON_SIZE) { DHLOGE("On parameter error, maybe empty or beyond MAX_JSON_SIZE"); return true; } @@ -325,7 +325,7 @@ bool JsonLengthInvalid(const std::string &jsonStr) template bool ArrayLengthInvalid(const std::vector &array) { - if (array.empty() || array.size() > MAX_ARR_SIZE){ + if (array.empty() || array.size() > MAX_ARR_SIZE) { DHLOGE("On parameter error, maybe empty or beyond MAX_ARR_SIZE"); return true; } @@ -336,7 +336,7 @@ bool ArrayLengthInvalid(const std::vector &array) bool KeySizeInvalid(const std::string &key) { - if (key.empty() || key.length() > MAX_KEY_SIZE){ + if (key.empty() || key.length() > MAX_KEY_SIZE) { DHLOGE("On parameter error, maybe empty or beyond MAX_KEY_SIZE"); return true; } @@ -347,7 +347,7 @@ bool KeySizeInvalid(const std::string &key) bool HashSizeInvalid(const std::string &hashValue) { - if (hashValue.empty() || hashValue.length() > MAX_HASH_SIZE){ + if (hashValue.empty() || hashValue.length() > MAX_HASH_SIZE) { DHLOGE("On parameter error, maybe empty or beyond MAX_HASH_SIZE"); return true; } -- Gitee From 95ab9991217a680c63749f21182e2daf529a0345 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Thu, 18 Jul 2024 19:32:02 +0800 Subject: [PATCH 4/6] third altering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- .../src/accessmanager/access_manager.cpp | 2 +- utils/src/dh_utils_tool.cpp | 29 +++++-------------- 2 files changed, 9 insertions(+), 22 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index 5ae3bd7e..6504e2ab 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -132,7 +132,7 @@ void AccessManager::OnDeviceOffline(const DmDeviceInfo &deviceInfo) auto networkId = std::string(deviceInfo.networkId); std::string uuid = DHContext::GetInstance().GetUUIDByNetworkId(networkId); std::string udid = DHContext::GetInstance().GetUDIDByNetworkId(networkId); - if (IdLengthInvalid(networkId, uuid, udid)) { + if (IdLengthInvalid(networkId || IdLengthInvalid(uuid) || IdLengthInvalid(udid)) { return; } diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index b6ba5185..3c627323 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -283,9 +283,7 @@ bool IdLengthInvalid(const std::string & input) DHLOGE("On parameter length error, maybe empty or beyond MAX_ID_LEN!"); return true; } - else { - return false; - } + return false; } bool MessageLengthInvalid(const std::string &input) @@ -294,9 +292,7 @@ bool MessageLengthInvalid(const std::string &input) DHLOGE("On parameter error, maybe empty or beyond MAX_MESSAGE_LEN!"); return true; } - else { - return false; - } + return false; } template @@ -306,9 +302,8 @@ bool RecordSizeInvalid(const std::vector &input) DHLOGE("On parameter error, maybe empty or beyond MAX_DE_RECORD_SIZE!"); return true; } - else { - return false; - } + return false; + } bool JsonLengthInvalid(const std::string &jsonStr) @@ -317,9 +312,7 @@ bool JsonLengthInvalid(const std::string &jsonStr) DHLOGE("On parameter error, maybe empty or beyond MAX_JSON_SIZE"); return true; } - else { - return false; - } + return false; } template @@ -329,9 +322,7 @@ bool ArrayLengthInvalid(const std::vector &array) DHLOGE("On parameter error, maybe empty or beyond MAX_ARR_SIZE"); return true; } - else { - return false; - } + return false; } bool KeySizeInvalid(const std::string &key) @@ -340,9 +331,7 @@ bool KeySizeInvalid(const std::string &key) DHLOGE("On parameter error, maybe empty or beyond MAX_KEY_SIZE"); return true; } - else { - return false; - } + return false; } bool HashSizeInvalid(const std::string &hashValue) @@ -351,9 +340,7 @@ bool HashSizeInvalid(const std::string &hashValue) DHLOGE("On parameter error, maybe empty or beyond MAX_HASH_SIZE"); return true; } - else { - return false; - } + return false; } } // namespace DistributedHardware } // namespace OHOS -- Gitee From 219ebdc9d1b3affa2aef94f1cebb85166356ba17 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Thu, 18 Jul 2024 19:53:43 +0800 Subject: [PATCH 5/6] fourth altering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- .../src/accessmanager/access_manager.cpp | 2 +- utils/src/dh_utils_tool.cpp | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp index 6504e2ab..35c65ecd 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -132,7 +132,7 @@ void AccessManager::OnDeviceOffline(const DmDeviceInfo &deviceInfo) auto networkId = std::string(deviceInfo.networkId); std::string uuid = DHContext::GetInstance().GetUUIDByNetworkId(networkId); std::string udid = DHContext::GetInstance().GetUDIDByNetworkId(networkId); - if (IdLengthInvalid(networkId || IdLengthInvalid(uuid) || IdLengthInvalid(udid)) { + if (IdLengthInvalid(networkId) || IdLengthInvalid(uuid) || IdLengthInvalid(udid)) { return; } diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index 3c627323..9a402c2f 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -277,7 +277,7 @@ bool GetSysPara(const char *key, bool &value) return true; } -bool IdLengthInvalid(const std::string & input) +bool IdLengthInvalid(const std::string &input) { if (input.empty() || input.length() > MAX_ID_LEN) { DHLOGE("On parameter length error, maybe empty or beyond MAX_ID_LEN!"); @@ -303,7 +303,6 @@ bool RecordSizeInvalid(const std::vector &input) return true; } return false; - } bool JsonLengthInvalid(const std::string &jsonStr) -- Gitee From fb7f3a2372919f1137f5e7037cbbcb0bd3dee466 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Thu, 18 Jul 2024 20:23:03 +0800 Subject: [PATCH 6/6] fifth altering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- utils/include/dh_utils_tool.h | 3 +-- utils/src/dh_utils_tool.cpp | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/utils/include/dh_utils_tool.h b/utils/include/dh_utils_tool.h index 9b6eb126..aa315d19 100644 --- a/utils/include/dh_utils_tool.h +++ b/utils/include/dh_utils_tool.h @@ -75,8 +75,7 @@ bool RecordSizeInvalid(const std::vector &input); bool JsonLengthInvalid(const std::string &jsonStr); -template -bool ArrayLengthInvalid(const std::vector &array); +bool ArrayLengthInvalid(const std::vector &array); bool KeySizeInvalid(const std::string &key); diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index 9a402c2f..69b8a667 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -277,7 +277,7 @@ bool GetSysPara(const char *key, bool &value) return true; } -bool IdLengthInvalid(const std::string &input) +bool IdLengthInvalid(const std::string &input) { if (input.empty() || input.length() > MAX_ID_LEN) { DHLOGE("On parameter length error, maybe empty or beyond MAX_ID_LEN!"); @@ -314,8 +314,7 @@ bool JsonLengthInvalid(const std::string &jsonStr) return false; } -template -bool ArrayLengthInvalid(const std::vector &array) +bool ArrayLengthInvalid(const std::vector &array) { if (array.empty() || array.size() > MAX_ARR_SIZE) { DHLOGE("On parameter error, maybe empty or beyond MAX_ARR_SIZE"); -- Gitee