diff --git a/common/include/utils/profile_utils.h b/common/include/utils/profile_utils.h index dbbe454ddbccbc903a6da67485d8e139334a6fe6..a80ba25c4e79a228defa2796faf7766cf3690e65 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 2030d3edc410189d95a914fedbe77b3ac7196209..fe3590cbdc79bc91337b803f82c369892b2960ce 100644 --- a/common/src/utils/profile_utils.cpp +++ b/common/src/utils/profile_utils.cpp @@ -362,6 +362,30 @@ bool ProfileUtils::IsCharProfileValid(const CharacteristicProfile& charProfile) IsKeyValid(charProfile.GetServiceName()) && IsKeyValid(charProfile.GetCharacteristicKey()); } +bool ProfileUtils::IsDeviceProfileValid(const DeviceProfile& devProfile) +{ + if (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 +727,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 +735,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 8bc739c054d08daa8b5e9ae849dd6947d324fedd..86a91fe29bc257e6243fb9f312de8bc084d3a308 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