From d4ccd43adc2206b769b29211f001c65b92c6c1c0 Mon Sep 17 00:00:00 2001 From: zhanglei Date: Tue, 24 Sep 2024 19:26:50 +0800 Subject: [PATCH 1/2] add Signed-off-by: zhanglei --- common/include/utils/profile_utils.h | 6 ++++ common/src/utils/profile_utils.cpp | 28 ++++++++++++++++++- .../core/src/utils/profile_control_utils.cpp | 12 ++++++++ 3 files changed, 45 insertions(+), 1 deletion(-) diff --git a/common/include/utils/profile_utils.h b/common/include/utils/profile_utils.h index dbbe454d..a80ba25c 100644 --- a/common/include/utils/profile_utils.h +++ b/common/include/utils/profile_utils.h @@ -54,6 +54,12 @@ public: static bool IsSvrProfileValid(const ServiceProfile& svrProfile); // This mothed can be invoked only when put or delete profile. static bool IsCharProfileValid(const CharacteristicProfile& charProfile); + // This mothed can be invoked only when get profile. + static bool IsDeviceProfileValid(const DeviceProfile& devProfile); + // This mothed can be invoked only when get profile. + static bool IsServiceProfileValid(const ServiceProfile& svrProfile); + // This mothed can be invoked only when get profile. + static bool IsCharacteristicProfileValid(const CharacteristicProfile& charProfile); static std::string GenerateDeviceProfileKey(const std::string& deviceId); static std::string GenerateServiceProfileKey(const std::string& deviceId, const std::string& serviceName); static std::string GenerateCharProfileKey(const std::string& deviceId, const std::string& serviceName, diff --git a/common/src/utils/profile_utils.cpp b/common/src/utils/profile_utils.cpp index 2030d3ed..2ba368ef 100644 --- a/common/src/utils/profile_utils.cpp +++ b/common/src/utils/profile_utils.cpp @@ -362,6 +362,31 @@ bool ProfileUtils::IsCharProfileValid(const CharacteristicProfile& charProfile) IsKeyValid(charProfile.GetServiceName()) && IsKeyValid(charProfile.GetCharacteristicKey()); } +bool ProfileUtils::IsDeviceProfileValid(const DeviceProfile& devProfile) +{ + if (devProfile.GetOsSysCap().empty() || devProfile.GetOsVersion().empty() || + devProfile.GetOsType() == MIN_OS_TYPE) { + return false; + } + return true; +} + +bool ProfileUtils::IsServiceProfileValid(const ServiceProfile& svrProfile) +{ + if (svrProfile.GetServiceName().empty() || svrProfile.GetServiceType().empty()) { + return false; + } + return true; +} + +bool ProfileUtils::IsCharacteristicProfileValid(const CharacteristicProfile& charProfile) +{ + if (charProfile.GetCharacteristicKey().empty() || charProfile.GetCharacteristicValue().empty()) { + return false; + } + return true; +} + std::string ProfileUtils::GenerateDeviceProfileKey(const std::string& deviceId) { return DEV_PREFIX + SEPARATOR + deviceId; @@ -703,6 +728,7 @@ bool ProfileUtils::IsPropertyValid(const std::map& pro (static_cast(propertyMap.at(property).length())) < maxValue) { return true; } + HILOGE("property is valid, property : %{public}s", property.c_str()); return false; } @@ -710,7 +736,7 @@ bool ProfileUtils::IsPropertyValid(const std::map& pro int32_t minValue, int32_t maxValue) { if (property.empty() || propertyMap.find(property) == propertyMap.end()) { - HILOGE("property is valid"); + HILOGE("property is valid, property : %{public}s", property.c_str()); return false; } std::string propertyValue = propertyMap.at(property); diff --git a/services/core/src/utils/profile_control_utils.cpp b/services/core/src/utils/profile_control_utils.cpp index 8bc739c0..86a91fe2 100644 --- a/services/core/src/utils/profile_control_utils.cpp +++ b/services/core/src/utils/profile_control_utils.cpp @@ -244,6 +244,10 @@ int32_t ProfileControlUtils::GetDeviceProfile(std::shared_ptr kvStor return DP_GET_KV_DB_FAIL; } ProfileUtils::EntriesToDeviceProfile(values, deviceProfile); + if (!ProfileUtils::IsDeviceProfileValid(deviceProfile)) { + HILOGE("deviceProfile is invalid!"); + return DP_GET_KV_DB_FAIL; + } HILOGD("GetDeviceProfile in db : %{public}s!", deviceProfile.AnnoymizeDump().c_str()); return DP_SUCCESS; } @@ -273,6 +277,10 @@ int32_t ProfileControlUtils::GetServiceProfile(std::shared_ptr kvSto return DP_GET_KV_DB_FAIL; } ProfileUtils::EntriesToServiceProfile(values, serviceProfile); + if (!ProfileUtils::IsServiceProfileValid(serviceProfile)) { + HILOGE("serviceProfile is invalid!"); + return DP_GET_KV_DB_FAIL; + } HILOGD("GetServiceProfile in db : %{public}s!", serviceProfile.dump().c_str()); return DP_SUCCESS; } @@ -312,6 +320,10 @@ int32_t ProfileControlUtils::GetCharacteristicProfile(std::shared_ptr Date: Thu, 26 Sep 2024 14:06:55 +0800 Subject: [PATCH 2/2] add Signed-off-by: zhanglei --- common/src/utils/profile_utils.cpp | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/common/src/utils/profile_utils.cpp b/common/src/utils/profile_utils.cpp index 2ba368ef..fe3590cb 100644 --- a/common/src/utils/profile_utils.cpp +++ b/common/src/utils/profile_utils.cpp @@ -364,8 +364,7 @@ bool ProfileUtils::IsCharProfileValid(const CharacteristicProfile& charProfile) bool ProfileUtils::IsDeviceProfileValid(const DeviceProfile& devProfile) { - if (devProfile.GetOsSysCap().empty() || devProfile.GetOsVersion().empty() || - devProfile.GetOsType() == MIN_OS_TYPE) { + if (devProfile.GetOsVersion().empty() || devProfile.GetOsType() == MIN_OS_TYPE) { return false; } return true; -- Gitee