From 0bd140df65e85419c5a4139c34f8643acd64f22d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Wed, 24 Jul 2024 12:00:42 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E4=BE=9D=E6=8D=AE=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83=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 | 63 +++++++++-- .../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 | 6 + .../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 | 66 +++++++++-- .../src/resourcemanager/capability_utils.cpp | 4 + .../src/resourcemanager/db_adapter.cpp | 34 +++++- .../local_capability_info_manager.cpp | 31 +++++- .../resourcemanager/meta_capability_info.cpp | 7 ++ .../src/resourcemanager/meta_info_manager.cpp | 49 +++++++-- .../src/resourcemanager/version_info.cpp | 15 +++ .../resourcemanager/version_info_manager.cpp | 25 ++++- .../src/transport/dh_comm_tool.cpp | 2 +- .../src/transport/dh_transport.cpp | 25 +++++ .../src/transport/dh_transport_obj.cpp | 18 ++- .../src/utils/dh_context.cpp | 42 +++++-- .../src/versionmanager/version_manager.cpp | 13 +++ .../src/mock_hardware_handler.cpp | 2 +- utils/include/dh_utils_tool.h | 12 ++ utils/src/anonymous_string.cpp | 6 +- utils/src/dh_utils_tool.cpp | 63 ++++++++++- utils/src/histreamer_ability_parser.cpp | 104 +++++++++++++----- 41 files changed, 651 insertions(+), 130 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..40e6749c 100644 --- a/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp +++ b/interfaces/inner_kits/src/distributed_hardware_fwk_kit.cpp @@ -19,6 +19,7 @@ #include "anonymous_string.h" #include "constants.h" +#include "dh_utils_tool.h" #include "dhfwk_sa_manager.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" @@ -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 (!IsMessageLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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..1ac334d0 100644 --- a/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp +++ b/interfaces/inner_kits/src/ipc/dhfwk_sa_manager.cpp @@ -21,6 +21,7 @@ #include "system_ability_definition.h" #include "constants.h" +#include "dh_utils_tool.h" #include "distributed_hardware_log.h" #include "distributed_hardware_proxy.h" #include "distributed_hardware_errno.h" @@ -102,6 +103,9 @@ void DHFWKSAManager::RegisterSAStateCallback(DHFWKSAStateCb callback) void DHFWKSAManager::SystemAbilityListener::OnAddSystemAbility(int32_t systemAbilityId, const std::string &deviceId) { + if (!IsIdLengthValid(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 (!IsIdLengthValid(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..46b281b1 100644 --- a/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp +++ b/interfaces/inner_kits/src/ipc/distributed_hardware_proxy.cpp @@ -21,6 +21,7 @@ #include "anonymous_string.h" #include "av_trans_errno.h" #include "constants.h" +#include "dh_utils_tool.h" #include "dhardware_ipc_interface_code.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" @@ -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 (!IsMessageLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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..32b974cc 100644 --- a/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp +++ b/services/distributedhardwarefwkservice/src/accessmanager/access_manager.cpp @@ -130,14 +130,15 @@ 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!"); + if (!IsIdLengthValid(networkId)) { return; } std::string uuid = DHContext::GetInstance().GetUUIDByNetworkId(networkId); + if (!IsIdLengthValid(uuid)) { + return; + } 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 (!IsIdLengthValid(udid)) { return; } @@ -155,18 +156,15 @@ 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!"); + if (!IsIdLengthValid(networkId)) { return; } auto uuid = GetUUIDByDm(networkId); - if (uuid.size() == 0 || uuid.size() > MAX_ID_LEN) { - DHLOGE("Uuid is invalid!"); + if (!IsIdLengthValid(uuid)) { return; } auto udid = GetUDIDByDm(networkId); - if (udid.size() == 0 || udid.size() > MAX_ID_LEN) { - DHLOGE("Udid is invalid!"); + if (!IsIdLengthValid(udid)) { return; } auto ret = diff --git a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp index f9a6165e..847db350 100644 --- a/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp +++ b/services/distributedhardwarefwkservice/src/componentloader/component_loader.cpp @@ -116,22 +116,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; @@ -141,17 +141,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); @@ -161,17 +161,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); @@ -181,7 +181,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()); @@ -189,7 +189,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; @@ -253,6 +253,9 @@ bool ComponentLoader::CheckComponentEnable(const CompConfig &config) int32_t ComponentLoader::GetCompPathAndVersion(const std::string &jsonStr, std::map &dhtypeMap) { + if (!IsJsonLengthValid(jsonStr)) { + return ERR_DH_FWK_PARA_INVALID; + } cJSON *root = cJSON_Parse(jsonStr.c_str()); if (root == NULL) { DHLOGE("jsonStr parse failed"); @@ -337,7 +340,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; @@ -519,8 +522,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 (!IsMessageLengthValid(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..ad09679f 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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(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..ef10d2db 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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(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..62e670b7 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -516,9 +516,11 @@ bool ComponentManager::InitCompSink() int32_t ComponentManager::Enable(const std::string &networkId, const std::string &uuid, const std::string &dhId, const DHType dhType) { + if (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(dhId)) { + 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; } @@ -537,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; @@ -571,6 +571,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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(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 +593,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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(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 +642,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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid)) { + return ERR_DH_FWK_PARA_INVALID; + } DeviceInfo sourceDeviceInfo = GetLocalDeviceInfo(); std::vector> sourceCapInfos; std::string sourceDHId; @@ -682,6 +691,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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid)) { + return ERR_DH_FWK_PARA_INVALID; + } DeviceInfo sourceDeviceInfo = GetLocalDeviceInfo(); std::vector> sourceMetaInfos; std::string sourceDHId; @@ -714,6 +726,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 (!IsIdLengthValid(uuid) || !IsIdLengthValid(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 +750,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 (!IsIdLengthValid(uuid) || !IsIdLengthValid(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 +766,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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(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 +795,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 (!IsIdLengthValid(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 +815,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 (!IsIdLengthValid(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 +840,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 (!IsIdLengthValid(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 +858,9 @@ int32_t ComponentManager::GetVersion(const std::string &uuid, DHType dhType, std void ComponentManager::UpdateVersionCache(const std::string &uuid, const VersionInfo &versionInfo) { + if (!IsIdLengthValid(uuid)) { + return; + } DHVersion dhVersion; dhVersion.uuid = uuid; dhVersion.dhVersion = versionInfo.dhVersion; @@ -914,6 +947,9 @@ std::map ComponentManager::GetDHSinkInstance( bool ComponentManager::IsIdenticalAccount(const std::string &networkId) { + if (!IsIdLengthValid(networkId)) { + return false; + } DmAuthForm authForm = DmAuthForm::INVALID_TYPE; std::vector deviceList; DeviceManager::GetInstance().GetTrustedDeviceList(DH_FWK_PKG_NAME, "", deviceList); @@ -935,6 +971,9 @@ bool ComponentManager::IsIdenticalAccount(const std::string &networkId) void ComponentManager::UpdateBusinessState(const std::string &networkId, const std::string &dhId, BusinessState state) { + if (!IsIdLengthValid(networkId) || !IsIdLengthValid(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 +995,9 @@ void ComponentManager::UpdateBusinessState(const std::string &networkId, const s BusinessState ComponentManager::QueryBusinessState(const std::string &uuid, const std::string &dhId) { + if (!IsIdLengthValid(uuid) || !IsIdLengthValid(dhId)) { + return BusinessState::UNKNOWN; + } std::lock_guard lock(bizStateMtx_); std::pair key = {uuid, dhId}; if (dhBizStates_.find(key) == dhBizStates_.end()) { @@ -967,8 +1009,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 (!IsIdLengthValid(networkId)) { return; } dhCommToolPtr_->TriggerReqFullDHCaps(networkId); @@ -1007,7 +1048,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..5b41fa5f 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_monitor.cpp @@ -24,7 +24,9 @@ #include "anonymous_string.h" #include "component_loader.h" #include "component_manager.h" +#include "constants.h" #include "device_type.h" +#include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" @@ -47,11 +49,17 @@ ComponentMonitor::~ComponentMonitor() void ComponentMonitor::CompSystemAbilityListener::OnAddSystemAbility(int32_t saId, const std::string &deviceId) { + if (!IsIdLengthValid(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 (!IsIdLengthValid(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..0f70946b 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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 d74cec39..9267f7cf 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/dh_data_sync_trigger_listener.cpp @@ -19,6 +19,7 @@ #include "anonymous_string.h" #include "component_manager.h" +#include "dh_utils_tool.h" #include "distributed_hardware_log.h" #include "event_handler.h" @@ -39,6 +40,9 @@ DHDataSyncTriggerListener::~DHDataSyncTriggerListener() void DHDataSyncTriggerListener::OnDataSyncTrigger(const std::string &networkId) { + if (!IsIdLengthValid(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..2b532fa5 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/dh_state_listener.cpp @@ -19,6 +19,7 @@ #include "anonymous_string.h" #include "component_manager.h" +#include "dh_utils_tool.h" #include "distributed_hardware_log.h" class ComponentManager; @@ -38,6 +39,9 @@ DHStateListener::~DHStateListener() void DHStateListener::OnStateChanged(const std::string &networkId, const std::string &dhId, const BusinessState state) { + if (!IsIdLengthValid(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..e421556a 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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(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 4d826ce7..3fe2ec44 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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(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."); @@ -181,6 +184,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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(udid)) { + return ERR_DH_FWK_PARA_INVALID; + } if (!isInit && !Init()) { DHLOGE("distributedHardwareMgr is null"); return ERR_DH_FWK_HARDWARE_MANAGER_INIT_FAILED; diff --git a/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp b/services/distributedhardwarefwkservice/src/distributed_hardware_service.cpp index 3f2bf503..7510e1bb 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 (!IsIdLengthValid(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 (!IsIdLengthValid(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..913727d8 100644 --- a/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp +++ b/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp @@ -13,6 +13,7 @@ * limitations under the License. */ +#include "dh_utils_tool.h" #include "enabled_comps_dump.h" namespace OHOS { @@ -21,6 +22,9 @@ IMPLEMENT_SINGLE_INSTANCE(EnabledCompsDump); void EnabledCompsDump::DumpEnabledComp(const std::string &networkId, const DHType dhType, const std::string &dhId) { + if (!IsIdLengthValid(networkId) || !IsIdLengthValid(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 (!IsIdLengthValid(networkId) || !IsIdLengthValid(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..6901d123 100644 --- a/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp +++ b/services/distributedhardwarefwkservice/src/ipc/publisher_listener_proxy.cpp @@ -14,6 +14,7 @@ */ #include "constants.h" +#include "dh_utils_tool.h" #include "distributed_hardware_log.h" #include "publisher_listener_proxy.h" @@ -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 (!IsMessageLengthValid(message)) { return; } diff --git a/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp b/services/distributedhardwarefwkservice/src/localhardwaremanager/local_hardware_manager.cpp index 1146c1d9..0588b87c 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 (!IsIdLengthValid(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..06a15d93 100644 --- a/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp +++ b/services/distributedhardwarefwkservice/src/localhardwaremanager/plugin_listener_impl.cpp @@ -20,6 +20,7 @@ #include "capability_info_manager.h" #include "constants.h" #include "dh_context.h" +#include "dh_utils_tool.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" #include "publisher.h" @@ -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 (!IsIdLengthValid(dhId) || !IsMessageLengthValid(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 (!IsIdLengthValid(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..d49b50e8 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 (!IsMessageLengthValid(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..e900767e 100644 --- a/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp +++ b/services/distributedhardwarefwkservice/src/publisher/publisher_item.cpp @@ -15,6 +15,7 @@ #include "constants.h" #include "publisher_item.h" +#include "dh_utils_tool.h" #include "distributed_hardware_log.h" namespace OHOS { @@ -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 (!IsMessageLengthValid(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..3f1994ca 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 (!IsJsonLengthValid(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 aef278d9..a2d8519a 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp @@ -120,6 +120,9 @@ int32_t CapabilityInfoManager::UnInit() int32_t CapabilityInfoManager::SyncDeviceInfoFromDB(const std::string &deviceId) { + if (!IsIdLengthValid(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) { @@ -131,8 +134,8 @@ 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 (dataVector.empty() || dataVector.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("On dataVector error, maybe empty or too large."); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -159,8 +162,8 @@ 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 (dataVector.empty() || dataVector.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("On dataVector error, maybe empty or too large."); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -186,8 +189,8 @@ 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 (resInfos.empty() || resInfos.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("ResInfo is empty or too large!"); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -227,6 +230,10 @@ int32_t CapabilityInfoManager::AddCapability(const std::vector> &resInfos) { + if (resInfos.empty() || resInfos.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("ResInfo is empty or too large!"); + return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); for (auto &resInfo : resInfos) { if (resInfo == nullptr) { @@ -241,8 +248,7 @@ int32_t CapabilityInfoManager::AddCapabilityInMem(const std::vector MAX_ID_LEN) { - DHLOGE("DeviceId is invalid!"); + if (!IsIdLengthValid(deviceId)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Remove capability device info, deviceId: %{public}s", GetAnonyString(deviceId).c_str()); @@ -270,6 +276,9 @@ int32_t CapabilityInfoManager::RemoveCapabilityInfoInDB(const std::string &devic int32_t CapabilityInfoManager::RemoveCapabilityInfoByKey(const std::string &key) { + if (!IsIdLengthValid(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) { @@ -289,6 +298,9 @@ int32_t CapabilityInfoManager::RemoveCapabilityInfoByKey(const std::string &key) int32_t CapabilityInfoManager::RemoveCapabilityInfoInMem(const std::string &deviceId) { + if (!IsIdLengthValid(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();) { @@ -370,6 +382,10 @@ void CapabilityInfoManager::OnChange(const DistributedKv::DataOrigin &origin, Ke void CapabilityInfoManager::HandleCapabilityAddChange(const std::vector &insertRecords) { + if (insertRecords.empty() || insertRecords.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("Records is empty or too large!"); + return; + } std::lock_guard lock(capInfoMgrMutex_); for (const auto &item : insertRecords) { const std::string value = item.value.ToString(); @@ -404,6 +420,10 @@ void CapabilityInfoManager::HandleCapabilityAddChange(const std::vector &updateRecords) { + if (updateRecords.empty() || updateRecords.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("Records is empty or too large!"); + return; + } if (DistributedHardwareManagerFactory::GetInstance().GetUnInitFlag()) { DHLOGE("no need Update, is in uniniting."); return; @@ -424,6 +444,10 @@ void CapabilityInfoManager::HandleCapabilityUpdateChange(const std::vector &deleteRecords) { + if (deleteRecords.empty() || deleteRecords.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("Records is empty or too large!"); + return; + } if (DistributedHardwareManagerFactory::GetInstance().GetUnInitFlag()) { DHLOGE("no need Update, is in uniniting."); return; @@ -467,6 +491,9 @@ bool CapabilityInfoManager::IsCapabilityMatchFilter(const std::shared_ptr> &resInfos) { + if (resInfos.empty() || resInfos.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("resInfo is empty or too large!"); + return; + } std::lock_guard lock(capInfoMgrMutex_); for (auto &capabilityInfo : globalCapInfoMap_) { if (IsCapKeyMatchDeviceId(capabilityInfo.first, deviceId)) { @@ -517,6 +548,9 @@ void CapabilityInfoManager::GetCapabilitiesByDeviceId(const std::string &deviceI bool CapabilityInfoManager::HasCapability(const std::string &deviceId, const std::string &dhId) { + if (!IsIdLengthValid(deviceId) || !IsIdLengthValid(dhId)) { + return false; + } std::lock_guard lock(capInfoMgrMutex_); std::string kvKey = GetCapabilityKey(deviceId, dhId); if (globalCapInfoMap_.find(kvKey) == globalCapInfoMap_.end()) { @@ -528,6 +562,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 (!IsIdLengthValid(deviceId) || !IsIdLengthValid(dhId)) { + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); std::string key = GetCapabilityKey(deviceId, dhId); if (globalCapInfoMap_.find(key) == globalCapInfoMap_.end()) { @@ -540,6 +577,9 @@ int32_t CapabilityInfoManager::GetCapability(const std::string &deviceId, const int32_t CapabilityInfoManager::GetDataByKey(const std::string &key, std::shared_ptr &capInfoPtr) { + if (!IsIdLengthValid(key)) { + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGI("dbAdapterPtr_ is null"); @@ -567,6 +607,9 @@ int32_t CapabilityInfoManager::GetDataByDHType(const DHType dhType, CapabilityIn int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, CapabilityInfoMap &capabilityMap) { + if (!IsIdLengthValid(keyPrefix)) { + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); @@ -577,8 +620,8 @@ 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 (dataVector.empty() || dataVector.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("On dataVector error, maybe empty or too large."); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -602,6 +645,9 @@ void CapabilityInfoManager::DumpCapabilityInfos(std::vector &cap std::vector CapabilityInfoManager::GetEntriesByKeys(const std::vector &keys) { + if (!IsArrayLengthValid(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..4c0b0843 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_utils.cpp @@ -17,6 +17,7 @@ #include "capability_info.h" #include "constants.h" +#include "dh_utils_tool.h" #include "distributed_hardware_errno.h" namespace OHOS { @@ -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 (!IsIdLengthValid(key) || !IsIdLengthValid(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..abc33994 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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(key) || !IsMessageLengthValid(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 (!IsIdLengthValid(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,9 @@ 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 (allEntries.empty() || allEntries.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("AllEntries is empty or too large!"); + return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto& item : allEntries) { values.push_back(item.value.ToString()); @@ -300,8 +313,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 (!IsIdLengthValid(key) || !IsMessageLengthValid(value)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(dbAdapterMutex_); @@ -321,6 +333,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 (!IsArrayLengthValid(keys) || !IsArrayLengthValid(values)) { + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); @@ -471,6 +486,9 @@ void DBAdapter::DeleteKvStore() int32_t DBAdapter::RemoveDeviceData(const std::string &deviceId) { + if (!IsIdLengthValid(deviceId)) { + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); @@ -487,6 +505,9 @@ int32_t DBAdapter::RemoveDeviceData(const std::string &deviceId) int32_t DBAdapter::RemoveDataByKey(const std::string &key) { + if (!IsIdLengthValid(key)) { + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { DHLOGE("kvStoragePtr_ is null"); @@ -504,6 +525,9 @@ int32_t DBAdapter::RemoveDataByKey(const std::string &key) std::vector DBAdapter::GetEntriesByKeys(const std::vector &keys) { + if (!IsArrayLengthValid(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..6f46a84d 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 (!IsIdLengthValid(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,8 @@ 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 (dataVector.empty() || dataVector.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("On dataVector error, maybe empty or too large."); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -111,8 +114,8 @@ 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 (resInfos.empty() || resInfos.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("resInfo is empty or too large!"); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); @@ -146,6 +149,9 @@ int32_t LocalCapabilityInfoManager::AddCapability(const std::vector lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -166,6 +172,10 @@ int32_t LocalCapabilityInfoManager::RemoveCapabilityInfoByKey(const std::string void LocalCapabilityInfoManager::GetCapabilitiesByDeviceId(const std::string &deviceId, std::vector> &resInfos) { + if (!IsIdLengthValid(deviceId) || resInfos.empty() || resInfos.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("On parameter error, maybe empty or too large!"); + return; + } std::lock_guard lock(capInfoMgrMutex_); for (auto &capabilityInfo : globalCapInfoMap_) { if (IsCapKeyMatchDeviceId(capabilityInfo.first, deviceId)) { @@ -177,6 +187,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 (!IsIdLengthValid(deviceId) || !IsIdLengthValid(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 +202,9 @@ int32_t LocalCapabilityInfoManager::GetCapability(const std::string &deviceId, c int32_t LocalCapabilityInfoManager::GetDataByKey(const std::string &key, std::shared_ptr &capInfoPtr) { + if (!IsIdLengthValid(key)) { + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGI("dbAdapterPtr_ is null"); @@ -216,6 +232,9 @@ int32_t LocalCapabilityInfoManager::GetDataByDHType(const DHType dhType, Capabil int32_t LocalCapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, CapabilityInfoMap &capabilityMap) { + if (!IsKeySizeValid(keyPrefix)) { + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); @@ -226,8 +245,8 @@ 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 (dataVector.empty() || dataVector.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("On dataVector error, maybe empty or too large!"); 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..fc08bc62 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 (!IsJsonLengthValid(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()); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp index 7eddc2ad..236845c1 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp @@ -116,8 +116,8 @@ 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 (metaCapInfos.empty() || metaCapInfos.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("MetaCapInfos is empty or too large!"); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } std::lock_guard lock(metaInfoMgrMutex_); @@ -156,6 +156,9 @@ int32_t MetaInfoManager::AddMetaCapInfos(const std::vector lock(metaInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { @@ -167,8 +170,8 @@ 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 (dataVector.empty() || dataVector.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("On dataVector error, maybe empty or too large."); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -195,8 +198,8 @@ 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 (dataVector.empty() || dataVector.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("On dataVector error, maybe empty or too large."); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -224,6 +227,9 @@ int32_t MetaInfoManager::SyncRemoteMetaInfos() int32_t MetaInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, MetaCapInfoMap &metaCapMap) { + if (!IsKeySizeValid(keyPrefix)) { + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(metaInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); @@ -234,8 +240,8 @@ 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 (dataVector.empty() || dataVector.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("On dataVector error, maybe empty or too large."); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -251,6 +257,9 @@ int32_t MetaInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, MetaCa int32_t MetaInfoManager::RemoveMetaInfoByKey(const std::string &key) { + if (!IsKeySizeValid(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 +278,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 (!IsHashSizeValid(udidHash) || !IsIdLengthValid(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 +294,9 @@ int32_t MetaInfoManager::GetMetaCapInfo(const std::string &udidHash, void MetaInfoManager::GetMetaCapInfosByUdidHash(const std::string &udidHash, std::vector> &metaCapInfos) { + if (!IsHashSizeValid(udidHash)) { + return; + } std::lock_guard lock(metaInfoMgrMutex_); for (auto &metaCapInfo : globalMetaInfoMap_) { if (IsCapKeyMatchDeviceId(metaCapInfo.first, udidHash)) { @@ -292,6 +307,9 @@ void MetaInfoManager::GetMetaCapInfosByUdidHash(const std::string &udidHash, int32_t MetaInfoManager::GetMetaCapByValue(const std::string &value, std::shared_ptr &metaCapPtr) { + if (!IsMessageLengthValid(value)) { + return ERR_DH_FWK_PARA_INVALID; + } if (metaCapPtr == nullptr) { metaCapPtr = std::make_shared(); } @@ -347,6 +365,10 @@ void MetaInfoManager::OnChange(const DistributedKv::DataOrigin &origin, Keys &&k void MetaInfoManager::HandleMetaCapabilityAddChange(const std::vector &insertRecords) { + if (insertRecords.empty() || insertRecords.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("Records is empty or too large!"); + return; + } std::lock_guard lock(metaInfoMgrMutex_); for (const auto &item : insertRecords) { const std::string value = item.value.ToString(); @@ -381,6 +403,10 @@ void MetaInfoManager::HandleMetaCapabilityAddChange(const std::vector &updateRecords) { + if (updateRecords.empty() || updateRecords.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("Records is empty or too large!"); + return; + } std::lock_guard lock(metaInfoMgrMutex_); for (const auto &item : updateRecords) { const std::string value = item.value.ToString(); @@ -397,6 +423,10 @@ void MetaInfoManager::HandleMetaCapabilityUpdateChange(const std::vector &deleteRecords) { + if (deleteRecords.empty() || deleteRecords.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("Records is empty or too large!"); + return; + } std::lock_guard lock(metaInfoMgrMutex_); for (const auto &item : deleteRecords) { const std::string value = item.value.ToString(); @@ -413,6 +443,9 @@ void MetaInfoManager::HandleMetaCapabilityDeleteChange(const std::vector MetaInfoManager::GetEntriesByKeys(const std::vector &keys) { + if (!IsArrayLengthValid(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..e5adb40a 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 (!IsJsonLengthValid(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..74ac0438 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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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,8 @@ 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 (dataVector.empty() || dataVector.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("On dataVector error, maybe empty or too large."); return ERR_DH_FWK_RESOURCE_RES_DB_DATA_INVALID; } for (const auto &data : dataVector) { @@ -274,6 +283,10 @@ void VersionInfoManager::OnChange(const DistributedKv::ChangeNotification &chang void VersionInfoManager::HandleVersionAddChange(const std::vector &insertRecords) { + if (insertRecords.empty() || insertRecords.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("Records is empty or too large!"); + return; + } DHLOGI("Version add change"); for (const auto &item : insertRecords) { const std::string value = item.value.ToString(); @@ -287,6 +300,10 @@ void VersionInfoManager::HandleVersionAddChange(const std::vector &updateRecords) { + if (updateRecords.empty() || updateRecords.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("Records is empty or too large!"); + return; + } DHLOGI("Version update change"); for (const auto &item : updateRecords) { const std::string value = item.value.ToString(); @@ -300,6 +317,10 @@ void VersionInfoManager::HandleVersionUpdateChange(const std::vector &deleteRecords) { + if (deleteRecords.empty() || deleteRecords.size() > MAX_DB_RECORD_SIZE) { + DHLOGE("Records is empty or too large!"); + 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..c4f90363 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 (!IsMessageLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(remoteDevId)) { + return; + } std::lock_guard lock(rmtSocketIdMtx_); remoteDevSocketIds_.erase(remoteDevId); } int32_t DHTransport::StartSocket(const std::string &remoteNetworkId) { + if (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(remoteNetworkId) || !IsMessageLengthValid(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..323bc049 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp @@ -14,14 +14,18 @@ */ #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 +46,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 +69,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 +80,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..d8327148 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 (!IsIdLengthValid(udid) || !IsIdLengthValid(uuid) || !IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsMessageLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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..464cd1e4 100644 --- a/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp +++ b/services/distributedhardwarefwkservice/src/versionmanager/version_manager.cpp @@ -18,6 +18,7 @@ #include "anonymous_string.h" #include "component_loader.h" #include "dh_context.h" +#include "dh_utils_tool.h" #include "distributed_hardware_log.h" namespace OHOS { @@ -60,6 +61,9 @@ void VersionManager::ShowLocalVersion(const DHVersion &dhVersion) const int32_t VersionManager::AddDHVersion(const std::string &uuid, const DHVersion &dhVersion) { + if (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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 (!IsIdLengthValid(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..b1b667a9 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 @@ -14,8 +14,8 @@ */ #include "mock_hardware_handler.h" - #include "distributed_hardware_errno.h" +#include "distributed_hardware_log.h" namespace OHOS { namespace DistributedHardware { diff --git a/utils/include/dh_utils_tool.h b/utils/include/dh_utils_tool.h index c52e1c45..ddb7a497 100644 --- a/utils/include/dh_utils_tool.h +++ b/utils/include/dh_utils_tool.h @@ -65,6 +65,18 @@ std::string Compress(const std::string& data); std::string Decompress(const std::string& data); bool GetSysPara(const char *key, bool &value); + +bool IsIdLengthValid(const std::string &input); + +bool IsMessageLengthValid(const std::string &input); + +bool IsJsonLengthValid(const std::string &jsonStr); + +bool IsArrayLengthValid(const std::vector &array); + +bool IsKeySizeValid(const std::string &key); + +bool IsHashSizeValid(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..8984f4a4 100644 --- a/utils/src/anonymous_string.cpp +++ b/utils/src/anonymous_string.cpp @@ -18,6 +18,10 @@ #include #include +#include "constants.h" +#include "dh_utils_tool.h" +#include "distributed_hardware_errno.h" +#include "distributed_hardware_log.h" #include "securec.h" namespace OHOS { @@ -30,7 +34,7 @@ namespace { } std::string GetAnonyString(const std::string &value) { - if (value.empty()) { + if (!IsMessageLengthValid(value)) { return ""; } std::string res; diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index be684494..f79425fe 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -25,14 +25,13 @@ #include #include -#include "openssl/sha.h" -#include "parameter.h" -#include "device_manager.h" -#include "dm_device_info.h" - #include "constants.h" +#include "device_manager.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" +#include "dm_device_info.h" +#include "openssl/sha.h" +#include "parameter.h" namespace OHOS { namespace DistributedHardware { @@ -286,5 +285,59 @@ bool GetSysPara(const char *key, bool &value) valueStr >> std::boolalpha >> value; return true; } + +bool IsIdLengthValid(const std::string &inputID) +{ + if (inputID.empty() || inputID.length() > MAX_ID_LEN) { + DHLOGE("On parameter length error, maybe empty or beyond MAX_ID_LEN!"); + return false; + } + return true; +} + +bool IsMessageLengthValid(const std::string &inputMessage) +{ + if (inputMessage.empty() || inputMessage.length() > MAX_MESSAGE_LEN) { + DHLOGE("On parameter error, maybe empty or beyond MAX_MESSAGE_LEN!"); + return false; + } + return true; +} + +bool JsonLengthInvalid(const std::string &inputJsonStr) +{ + if (inputJsonStr.empty() || inputJsonStr.length() > MAX_JSON_SIZE) { + DHLOGE("On parameter error, maybe empty or beyond MAX_JSON_SIZE"); + return false; + } + return true; +} + +bool IsArrayLengthValid(const std::vector &inputArray) +{ + if (inputArray.empty() || inputArray.size() > MAX_ARR_SIZE) { + DHLOGE("On parameter error, maybe empty or beyond MAX_ARR_SIZE"); + return false; + } + return true; +} + +bool KeySizeInvalid(const std::string &inputKey) +{ + if (inputKey.empty() || inputKey.length() > MAX_KEY_SIZE) { + DHLOGE("On parameter error, maybe empty or beyond MAX_KEY_SIZE"); + return false; + } + return true; +} + +bool HashSizeInvalid(const std::string &inputHashValue) +{ + if (inputHashValue.empty() || inputHashValue.length() > MAX_HASH_SIZE) { + DHLOGE("On parameter error, maybe empty or beyond MAX_HASH_SIZE"); + return false; + } + return true; +} } // 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 f0a694983623a2d4fb51d65eb6dbc0e98ba32391 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Wed, 24 Jul 2024 12:09:40 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E4=BE=9D=E6=8D=AE=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- .../src/transport/dh_transport_obj.cpp | 1 + .../pluginlistenerimpl/src/mock_hardware_handler.cpp | 1 + utils/src/dh_utils_tool.cpp | 11 +++++++---- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp b/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp index 323bc049..467075f5 100644 --- a/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp +++ b/services/distributedhardwarefwkservice/src/transport/dh_transport_obj.cpp @@ -14,6 +14,7 @@ */ #include "dh_transport_obj.h" + #include "dh_utils_tool.h" #include "distributed_hardware_log.h" 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 b1b667a9..0f35b104 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 @@ -14,6 +14,7 @@ */ #include "mock_hardware_handler.h" + #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index f79425fe..b0b6e119 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -25,13 +25,16 @@ #include #include -#include "constants.h" +#include "openssl/sha.h" +#include "parameter.h" + #include "device_manager.h" +#include "dm_device_info.h" + +#include "constants.h" #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" -#include "dm_device_info.h" -#include "openssl/sha.h" -#include "parameter.h" + namespace OHOS { namespace DistributedHardware { -- Gitee From 720d7b6cce87dcb4f3e4e65c01b5e2ae9ceef637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Wed, 24 Jul 2024 14:07:50 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- utils/src/dh_utils_tool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index b0b6e119..396df21a 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -307,7 +307,7 @@ bool IsMessageLengthValid(const std::string &inputMessage) return true; } -bool JsonLengthInvalid(const std::string &inputJsonStr) +bool IsJsonLengthvalid(const std::string &inputJsonStr) { if (inputJsonStr.empty() || inputJsonStr.length() > MAX_JSON_SIZE) { DHLOGE("On parameter error, maybe empty or beyond MAX_JSON_SIZE"); -- Gitee From 58d6602c2fb384b6108cf1e3c1c806ff464dd221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Wed, 24 Jul 2024 14:30:16 +0800 Subject: [PATCH 04/11] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- utils/src/dh_utils_tool.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index 396df21a..336a6224 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -84,7 +84,7 @@ std::string GetRandomID() std::string GetUUIDByDm(const std::string &networkId) { - if (networkId.empty()) { + if (!IsIdLengthValid(networkId)) { return ""; } std::string uuid = ""; @@ -94,7 +94,7 @@ std::string GetUUIDByDm(const std::string &networkId) std::string GetUDIDByDm(const std::string &networkId) { - if (networkId.empty()) { + if (!IsIdLengthValid(networkId)) { return ""; } std::string udid = ""; @@ -104,7 +104,7 @@ std::string GetUDIDByDm(const std::string &networkId) std::string GetDeviceIdByUUID(const std::string &uuid) { - if (uuid.size() == 0 || uuid.size() > MAX_ID_LEN) { + if (!IsIdLengthValid(uuid)) { DHLOGE("uuid is invalid!"); return ""; } @@ -325,7 +325,7 @@ bool IsArrayLengthValid(const std::vector &inputArray) return true; } -bool KeySizeInvalid(const std::string &inputKey) +bool IsKeySizeValid(const std::string &inputKey) { if (inputKey.empty() || inputKey.length() > MAX_KEY_SIZE) { DHLOGE("On parameter error, maybe empty or beyond MAX_KEY_SIZE"); @@ -334,7 +334,7 @@ bool KeySizeInvalid(const std::string &inputKey) return true; } -bool HashSizeInvalid(const std::string &inputHashValue) +bool IsHashSizeValid(const std::string &inputHashValue) { if (inputHashValue.empty() || inputHashValue.length() > MAX_HASH_SIZE) { DHLOGE("On parameter error, maybe empty or beyond MAX_HASH_SIZE"); -- Gitee From 71bc506dc565ada1508b63ce1d8b2e4121c2e504 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Wed, 24 Jul 2024 14:46:34 +0800 Subject: [PATCH 05/11] =?UTF-8?q?=E6=A0=B9=E6=8D=AE=E7=BC=96=E7=A0=81?= =?UTF-8?q?=E8=A7=84=E8=8C=83=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- utils/src/dh_utils_tool.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index 336a6224..4c76b1ab 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -307,7 +307,7 @@ bool IsMessageLengthValid(const std::string &inputMessage) return true; } -bool IsJsonLengthvalid(const std::string &inputJsonStr) +bool IsJsonLengthValid(const std::string &inputJsonStr) { if (inputJsonStr.empty() || inputJsonStr.length() > MAX_JSON_SIZE) { DHLOGE("On parameter error, maybe empty or beyond MAX_JSON_SIZE"); -- Gitee From 5a229a9e1ba1b3cc0ed474bfceab4101cd0f02ad Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Tue, 30 Jul 2024 10:12:57 +0800 Subject: [PATCH 06/11] =?UTF-8?q?=E5=8D=95=E5=85=83=E6=B5=8B=E8=AF=95?= =?UTF-8?q?=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- .../componentmanager/component_manager.cpp | 2 +- .../src/hidumphelper/enabled_comps_dump.cpp | 3 -- .../capability_info_manager.cpp | 9 +----- .../src/resourcemanager/db_adapter.cpp | 5 +--- .../accessmanager/access_manager_test.cpp | 8 ++++- .../src/component_manager_test.cpp | 2 +- .../src/resource_manager_test.cpp | 29 +++++++++++++++++-- .../src/version_info_manager_test.cpp | 21 ++++++++++++-- 8 files changed, 56 insertions(+), 23 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp index 62e670b7..05c3ebdf 100644 --- a/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp +++ b/services/distributedhardwarefwkservice/src/componentmanager/component_manager.cpp @@ -767,7 +767,7 @@ int32_t ComponentManager::GetEnableParam(const std::string &networkId, const std const std::string &dhId, DHType dhType, EnableParam ¶m) { if (!IsIdLengthValid(networkId) || !IsIdLengthValid(uuid) || !IsIdLengthValid(dhId)) { - return ERR_DH_FWK_PARA_INVALID; + return ERR_DH_FWK_COMPONENT_GET_ENABLE_PARAM_FAILED; } 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); diff --git a/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp b/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp index 913727d8..b8c95fe6 100644 --- a/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp +++ b/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp @@ -22,9 +22,6 @@ IMPLEMENT_SINGLE_INSTANCE(EnabledCompsDump); void EnabledCompsDump::DumpEnabledComp(const std::string &networkId, const DHType dhType, const std::string &dhId) { - if (!IsIdLengthValid(networkId) || !IsIdLengthValid(dhId)) { - return; - } HidumpCompInfo info(networkId, dhType, dhId); std::lock_guard lock(compInfosMutex_); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp index a2d8519a..b7fed356 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp @@ -491,9 +491,6 @@ bool CapabilityInfoManager::IsCapabilityMatchFilter(const std::shared_ptr> &resInfos) { - if (resInfos.empty() || resInfos.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("resInfo is empty or too large!"); + if (!IsIdLengthValid(deviceId)) { return; } std::lock_guard lock(capInfoMgrMutex_); @@ -607,9 +603,6 @@ int32_t CapabilityInfoManager::GetDataByDHType(const DHType dhType, CapabilityIn int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, CapabilityInfoMap &capabilityMap) { - if (!IsIdLengthValid(keyPrefix)) { - return ERR_DH_FWK_PARA_INVALID; - } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp index abc33994..f063cffd 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp @@ -239,7 +239,7 @@ void DBAdapter::SyncByNotFound(const std::string &key) int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) { - if (!IsIdLengthValid(key) || !IsMessageLengthValid(data)) { + if (!IsIdLengthValid(key)) { return ERR_DH_FWK_PARA_INVALID; } DHLOGI("Get data by key: %{public}s, storeId: %{public}s, dataType: %{public}d", @@ -272,9 +272,6 @@ int32_t DBAdapter::GetDataByKey(const std::string &key, std::string &data) int32_t DBAdapter::GetDataByKeyPrefix(const std::string &keyPrefix, std::vector &values) { - if (!IsIdLengthValid(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_); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp index 16bf3123..18592db6 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp @@ -83,9 +83,15 @@ HWTEST_F(AccessManagerTest, SendOnLineEvent_001, TestSize.Level1) HWTEST_F(AccessManagerTest, SendOffLineEvent_001, TestSize.Level1) { DHContext::GetInstance().devIdEntrySet_.clear(); + auto ret = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent("", TEST_UUID, TEST_UDID, + TEST_DEV_TYPE_PAD); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); auto ret = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(TEST_NETWORKID, "", TEST_UDID, TEST_DEV_TYPE_PAD); - EXPECT_EQ(ERR_DH_FWK_HARDWARE_MANAGER_DEVICE_REPEAT_OFFLINE, ret); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); + auto ret = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(TEST_NETWORKID, TEST_UUID, "", + TEST_DEV_TYPE_PAD); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); DHContext::GetInstance().AddOnlineDevice(TEST_UDID, TEST_UUID, TEST_NETWORKID); ret = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(TEST_NETWORKID, TEST_UUID, TEST_UDID, diff --git a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp index 0693a52c..f3d4a300 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/componentmanager/component_manager/src/component_manager_test.cpp @@ -460,7 +460,7 @@ HWTEST_F(ComponentManagerTest, Enable_002, TestSize.Level0) IDistributedHardwareSource *sourcePtr = nullptr; ComponentManager::GetInstance().compSource_.insert(std::make_pair(dhType, sourcePtr)); int32_t ret = ComponentManager::GetInstance().Enable(networkId, uuid, dhId, dhType); - EXPECT_EQ(ERR_DH_FWK_COMPONENT_GET_ENABLE_PARAM_FAILED, ret); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } /** diff --git a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp index 7d842a73..314f2712 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp @@ -312,6 +312,8 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_009, TestSize.Level0) HWTEST_F(ResourceManagerTest, resource_manager_test_010, TestSize.Level0) { vector> capInfos; + CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId("", capInfos); + EXPECT_EQ(capInfos.empty(), true); CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(DEV_ID_0, capInfos); EXPECT_EQ(capInfos.size(), TEST_SIZE_5); CapabilityInfoManager::GetInstance()->GetCapabilitiesByDeviceId(DEV_ID_1, capInfos); @@ -416,6 +418,11 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_015, TestSize.Level0) std::string value = ""; std::shared_ptr capPtr = nullptr; int32_t ret = GetCapabilityByValue(value, capPtr); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); + + value = "invalid JSON string"; + capPtr = nullptr; + ret = GetCapabilityByValue(value, capPtr); EXPECT_EQ(ERR_DH_FWK_JSON_PARSE_FAILED, ret); } @@ -470,6 +477,10 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_019, TestSize.Level0) CapabilityInfo capaInfo; std::string jsonStr = ""; int32_t ret = capaInfo.FromJsonString(jsonStr); + EZPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); + + jsonStr = "invalid JSON string"; + ret = capaInfo.FromJsonString(jsonStr); EXPECT_EQ(ERR_DH_FWK_JSON_PARSE_FAILED, ret); } @@ -785,11 +796,16 @@ HWTEST_F(ResourceManagerTest, HandleCapabilityDeleteChange_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, GetDataByKey_001, TestSize.Level0) { - std::string key; + std::string key = "000"; std::shared_ptr capInfoPtr; CapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; int32_t ret = CapabilityInfoManager::GetInstance()->GetDataByKey(key, capInfoPtr); EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); + + key = ""; + CapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; + ret = CapabilityInfoManager::GetInstance()->GetDataByKey(key, capInfoPtr); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } /** @@ -800,11 +816,16 @@ HWTEST_F(ResourceManagerTest, GetDataByKey_001, TestSize.Level0) */ HWTEST_F(ResourceManagerTest, GetDataByKeyPrefix_001, TestSize.Level0) { - std::string keyPrefix; + std::string keyPrefix = "000"; CapabilityInfoMap capabilityMap; CapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; int32_t ret = CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, capabilityMap); EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); + + keyPrefix = ""; + CapabilityInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; + ret = CapabilityInfoManager::GetInstance()->GetDataByKeyPrefix(keyPrefix, capabilityMap); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } /** @@ -1097,6 +1118,10 @@ HWTEST_F(ResourceManagerTest, GetMetaCapByValue_001, TestSize.Level0) metaCapPtr = std::make_shared( dhId, deviceId, "devName_test", 14, DHType::CAMERA, "attrs_test", "subtype", udidHash, "1.0"); ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); + + value = "invalid JSON string"; + ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr); EXPECT_EQ(ERR_DH_FWK_JSON_PARSE_FAILED, ret); } diff --git a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/versioninfomanager/src/version_info_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/versioninfomanager/src/version_info_manager_test.cpp index 8a60817f..10ea8481 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/versioninfomanager/src/version_info_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/versioninfomanager/versioninfomanager/src/version_info_manager_test.cpp @@ -220,10 +220,15 @@ HWTEST_F(VersionInfoManagerTest, UpdateVersionCache_002, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, RemoveVersionInfoByDeviceId_001, TestSize.Level0) { - std::string deviceId; + std::string deviceId = DEV_ID_1; VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; int32_t ret = VersionInfoManager::GetInstance()->RemoveVersionInfoByDeviceId(deviceId); EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); + + deviceId = ""; + VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; + ret = VersionInfoManager::GetInstance()->RemoveVersionInfoByDeviceId(deviceId); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } /** @@ -251,10 +256,15 @@ HWTEST_F(VersionInfoManagerTest, RemoveVersionInfoByDeviceId_002, TestSize.Level */ HWTEST_F(VersionInfoManagerTest, SyncVersionInfoFromDB_001, TestSize.Level0) { - std::string deviceId; + std::string deviceId = DEV_ID_1; VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; int32_t ret = VersionInfoManager::GetInstance()->SyncVersionInfoFromDB(deviceId); EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); + + deviceId = ""; + VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; + ret = VersionInfoManager::GetInstance()->SyncVersionInfoFromDB(deviceId); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } /** @@ -401,11 +411,16 @@ HWTEST_F(VersionInfoManagerTest, HandleVersionDeleteChange_001, TestSize.Level0) */ HWTEST_F(VersionInfoManagerTest, GetVersionInfoByDeviceId_001, TestSize.Level0) { - std::string deviceId; + std::string deviceId = DEV_ID_1; VersionInfo versionInfo; VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; int32_t ret = VersionInfoManager::GetInstance()->GetVersionInfoByDeviceId(deviceId, versionInfo); EXPECT_EQ(ERR_DH_FWK_RESOURCE_DB_ADAPTER_POINTER_NULL, ret); + + deviceId = ""; + VersionInfoManager::GetInstance()->dbAdapterPtr_ = nullptr; + ret = VersionInfoManager::GetInstance()->GetVersionInfoByDeviceId(deviceId, versionInfo); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); } } // namespace DistributedHardware -- Gitee From d8b401e0dcb4f0f52cfcb8aca703454f1ace20a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Tue, 30 Jul 2024 10:26:40 +0800 Subject: [PATCH 07/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=B1=E8=B4=A5UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- .../unittest/common/accessmanager/access_manager_test.cpp | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp index 18592db6..129a3963 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/accessmanager/access_manager_test.cpp @@ -86,10 +86,10 @@ HWTEST_F(AccessManagerTest, SendOffLineEvent_001, TestSize.Level1) auto ret = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent("", TEST_UUID, TEST_UDID, TEST_DEV_TYPE_PAD); EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); - auto ret = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(TEST_NETWORKID, "", TEST_UDID, + ret = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(TEST_NETWORKID, "", TEST_UDID, TEST_DEV_TYPE_PAD); EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); - auto ret = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(TEST_NETWORKID, TEST_UUID, "", + ret = DistributedHardwareManagerFactory::GetInstance().SendOffLineEvent(TEST_NETWORKID, TEST_UUID, "", TEST_DEV_TYPE_PAD); EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); -- Gitee From e8d4d16a26237f147e810af4593462b80295d8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Tue, 30 Jul 2024 10:52:20 +0800 Subject: [PATCH 08/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=B1=E8=B4=A5UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- .../common/resourcemanager/src/resource_manager_test.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp index 314f2712..23116092 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp @@ -477,7 +477,7 @@ HWTEST_F(ResourceManagerTest, resource_manager_test_019, TestSize.Level0) CapabilityInfo capaInfo; std::string jsonStr = ""; int32_t ret = capaInfo.FromJsonString(jsonStr); - EZPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); jsonStr = "invalid JSON string"; ret = capaInfo.FromJsonString(jsonStr); -- Gitee From ab216b29406f6f789092747c85e46d0977b208cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Tue, 30 Jul 2024 14:58:07 +0800 Subject: [PATCH 09/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=B1=E8=B4=A5UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- .../src/hidumphelper/enabled_comps_dump.cpp | 3 --- .../src/resourcemanager/capability_info_manager.cpp | 3 +++ .../common/resourcemanager/src/resource_manager_test.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp b/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp index b8c95fe6..d7f62755 100644 --- a/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp +++ b/services/distributedhardwarefwkservice/src/hidumphelper/enabled_comps_dump.cpp @@ -30,9 +30,6 @@ void EnabledCompsDump::DumpEnabledComp(const std::string &networkId, const DHTyp void EnabledCompsDump::DumpDisabledComp(const std::string &networkId, const DHType dhType, const std::string &dhId) { - if (!IsIdLengthValid(networkId) || !IsIdLengthValid(dhId)) { - return; - } HidumpCompInfo info(networkId, dhType, dhId); std::lock_guard lock(compInfosMutex_); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp index b7fed356..75956448 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp @@ -603,6 +603,9 @@ int32_t CapabilityInfoManager::GetDataByDHType(const DHType dhType, CapabilityIn int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, CapabilityInfoMap &capabilityMap) { + if (!IsIdLengthValid(key)) { + return ERR_DH_FWK_PARA_INVALID; + } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr is null"); diff --git a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp index 23116092..f2ed3426 100644 --- a/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp +++ b/services/distributedhardwarefwkservice/test/unittest/common/resourcemanager/src/resource_manager_test.cpp @@ -1110,7 +1110,7 @@ HWTEST_F(ResourceManagerTest, GetMetaCapByValue_001, TestSize.Level0) std::string value = ""; std::shared_ptr metaCapPtr = nullptr; auto ret = MetaInfoManager::GetInstance()->GetMetaCapByValue(value, metaCapPtr); - EXPECT_EQ(ERR_DH_FWK_JSON_PARSE_FAILED, ret); + EXPECT_EQ(ERR_DH_FWK_PARA_INVALID, ret); std::string deviceId = "deviceId_test"; std::string udidHash = "udidHash_test"; -- Gitee From f4e58b2be138846864703b10fd0a8a717c83033d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Tue, 30 Jul 2024 15:12:02 +0800 Subject: [PATCH 10/11] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E5=A4=B1=E8=B4=A5UT?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 行增 --- .../src/resourcemanager/capability_info_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp index 75956448..630c758d 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp @@ -603,7 +603,7 @@ int32_t CapabilityInfoManager::GetDataByDHType(const DHType dhType, CapabilityIn int32_t CapabilityInfoManager::GetDataByKeyPrefix(const std::string &keyPrefix, CapabilityInfoMap &capabilityMap) { - if (!IsIdLengthValid(key)) { + if (!IsIdLengthValid(keyPrefix)) { return ERR_DH_FWK_PARA_INVALID; } std::lock_guard lock(capInfoMgrMutex_); -- Gitee From f069a33f3a951f4b27b9e45662f4c65765de01d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=A1=8C=E5=A2=9E?= Date: Wed, 31 Jul 2024 11:42:27 +0800 Subject: [PATCH 11/11] =?UTF-8?q?=E4=BE=9D=E6=8D=AE=E6=A3=80=E8=A7=86?= =?UTF-8?q?=E6=84=8F=E8=A7=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: 行增 --- .../resourcemanager/capability_info_manager.cpp | 16 ---------------- .../src/resourcemanager/db_adapter.cpp | 4 ---- .../src/resourcemanager/meta_info_manager.cpp | 12 ------------ .../src/resourcemanager/version_info_manager.cpp | 12 ------------ utils/src/dh_utils_tool.cpp | 1 - 5 files changed, 45 deletions(-) diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp index 630c758d..39718990 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/capability_info_manager.cpp @@ -382,10 +382,6 @@ void CapabilityInfoManager::OnChange(const DistributedKv::DataOrigin &origin, Ke void CapabilityInfoManager::HandleCapabilityAddChange(const std::vector &insertRecords) { - if (insertRecords.empty() || insertRecords.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("Records is empty or too large!"); - return; - } std::lock_guard lock(capInfoMgrMutex_); for (const auto &item : insertRecords) { const std::string value = item.value.ToString(); @@ -420,10 +416,6 @@ void CapabilityInfoManager::HandleCapabilityAddChange(const std::vector &updateRecords) { - if (updateRecords.empty() || updateRecords.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("Records is empty or too large!"); - return; - } if (DistributedHardwareManagerFactory::GetInstance().GetUnInitFlag()) { DHLOGE("no need Update, is in uniniting."); return; @@ -444,10 +436,6 @@ void CapabilityInfoManager::HandleCapabilityUpdateChange(const std::vector &deleteRecords) { - if (deleteRecords.empty() || deleteRecords.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("Records is empty or too large!"); - return; - } if (DistributedHardwareManagerFactory::GetInstance().GetUnInitFlag()) { DHLOGE("no need Update, is in uniniting."); return; @@ -645,10 +633,6 @@ std::vector CapabilityInfoManager::GetEntriesByKeys(const return {}; } DHLOGI("call"); - if (keys.empty()) { - DHLOGE("keys empty."); - return {}; - } std::lock_guard lock(capInfoMgrMutex_); if (dbAdapterPtr_ == nullptr) { DHLOGE("dbAdapterPtr_ is null"); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp index f063cffd..89395e40 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/db_adapter.cpp @@ -527,10 +527,6 @@ std::vector DBAdapter::GetEntriesByKeys(const std::vector< } DHLOGI("call"); std::vector entries; - if (keys.empty()) { - DHLOGE("keys empty."); - return entries; - } { std::lock_guard lock(dbAdapterMutex_); if (kvStoragePtr_ == nullptr) { diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp index 236845c1..6bd60478 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/meta_info_manager.cpp @@ -365,10 +365,6 @@ void MetaInfoManager::OnChange(const DistributedKv::DataOrigin &origin, Keys &&k void MetaInfoManager::HandleMetaCapabilityAddChange(const std::vector &insertRecords) { - if (insertRecords.empty() || insertRecords.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("Records is empty or too large!"); - return; - } std::lock_guard lock(metaInfoMgrMutex_); for (const auto &item : insertRecords) { const std::string value = item.value.ToString(); @@ -403,10 +399,6 @@ void MetaInfoManager::HandleMetaCapabilityAddChange(const std::vector &updateRecords) { - if (updateRecords.empty() || updateRecords.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("Records is empty or too large!"); - return; - } std::lock_guard lock(metaInfoMgrMutex_); for (const auto &item : updateRecords) { const std::string value = item.value.ToString(); @@ -423,10 +415,6 @@ void MetaInfoManager::HandleMetaCapabilityUpdateChange(const std::vector &deleteRecords) { - if (deleteRecords.empty() || deleteRecords.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("Records is empty or too large!"); - return; - } std::lock_guard lock(metaInfoMgrMutex_); for (const auto &item : deleteRecords) { const std::string value = item.value.ToString(); diff --git a/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp b/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp index 74ac0438..bc90781e 100644 --- a/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp +++ b/services/distributedhardwarefwkservice/src/resourcemanager/version_info_manager.cpp @@ -283,10 +283,6 @@ void VersionInfoManager::OnChange(const DistributedKv::ChangeNotification &chang void VersionInfoManager::HandleVersionAddChange(const std::vector &insertRecords) { - if (insertRecords.empty() || insertRecords.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("Records is empty or too large!"); - return; - } DHLOGI("Version add change"); for (const auto &item : insertRecords) { const std::string value = item.value.ToString(); @@ -300,10 +296,6 @@ void VersionInfoManager::HandleVersionAddChange(const std::vector &updateRecords) { - if (updateRecords.empty() || updateRecords.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("Records is empty or too large!"); - return; - } DHLOGI("Version update change"); for (const auto &item : updateRecords) { const std::string value = item.value.ToString(); @@ -317,10 +309,6 @@ void VersionInfoManager::HandleVersionUpdateChange(const std::vector &deleteRecords) { - if (deleteRecords.empty() || deleteRecords.size() > MAX_DB_RECORD_SIZE) { - DHLOGE("Records is empty or too large!"); - return; - } DHLOGI("Version delete change"); for (const auto &item : deleteRecords) { const std::string value = item.value.ToString(); diff --git a/utils/src/dh_utils_tool.cpp b/utils/src/dh_utils_tool.cpp index 4c76b1ab..32603086 100644 --- a/utils/src/dh_utils_tool.cpp +++ b/utils/src/dh_utils_tool.cpp @@ -35,7 +35,6 @@ #include "distributed_hardware_errno.h" #include "distributed_hardware_log.h" - namespace OHOS { namespace DistributedHardware { namespace { -- Gitee