From 283b44e4324c72054e5465d286ef9120a665fb87 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Thu, 13 Mar 2025 11:57:43 +0800 Subject: [PATCH 1/8] =?UTF-8?q?=E4=BF=AE=E6=94=B9bindLevel=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 史晓晓 --- common/include/dm_anonymous.h | 1 + common/src/dm_anonymous.cpp | 14 ++++++++++++++ .../src/authentication/dm_auth_manager.cpp | 11 +++++------ 3 files changed, 20 insertions(+), 6 deletions(-) diff --git a/common/include/dm_anonymous.h b/common/include/dm_anonymous.h index 7eb62c0f5..5c29722e9 100644 --- a/common/include/dm_anonymous.h +++ b/common/include/dm_anonymous.h @@ -102,6 +102,7 @@ bool IsValueExist(const std::multimap unorderedmap, const bool IsDmCommonNotifyEventValid(DmCommonNotifyEvent dmCommonNotifyEvent); std::string SafetyDump(const nlohmann::json &jsonObj); std::string GetSubStr(const std::string &rawStr, const std::string &separator, int32_t index); +int32_t GetIntFromJsonString(const nlohmann::json &jsonObj, const std::string &key, int32_t defVal = 0); } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_ANONYMOUS_H diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 81e5a20a7..3a206ec21 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -395,5 +395,19 @@ std::string GetSubStr(const std::string &rawStr, const std::string &separator, i LOGE("get failed"); return ""; } + +int32_t GetIntFromJsonString(const nlohmann::json &jsonObj, const std::string &key, int32_t defVal) +{ + if (!IsString(jsonObj, key)) { + LOGE("%{public}s is not string", key); + return defVal; + } + std::string retValStr = jsonObject[key].get(); + if (!IsNumberString(retValStr)) { + LOGE("%{public}s is not number", key); + return defVal; + } + return std::atoi(retValStr.c_str()); +} } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 8edd9245f..23068ed8c 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -216,11 +216,11 @@ int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra, const return ERR_DM_INPUT_PARA_INVALID; } - if (jsonObject.is_discarded() || jsonObject.find(TAG_BIND_LEVEL) == jsonObject.end() || - !IsInt32(jsonObject, TAG_BIND_LEVEL)) { + if (jsonObject.is_discarded() || jsonObject.find(TAG_BIND_LEVEL) == jsonObject.end()) { return DM_OK; } - int32_t bindLevel = jsonObject[TAG_BIND_LEVEL].get(); + + int32_t bindLevel = GetIntFromJsonString(jsonObject, TAG_BIND_LEVEL, INVALID_TYPE); if (static_cast(bindLevel) > APP || bindLevel < INVALID_TYPE) { LOGE("bindlevel error %{public}d.", bindLevel); return ERR_DM_INPUT_PARA_INVALID; @@ -326,9 +326,8 @@ void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) if (IsString(jsonObject, APP_THUMBNAIL)) { authRequestContext_->appThumbnail = jsonObject[APP_THUMBNAIL].get(); } - if (IsInt32(jsonObject, TAG_BIND_LEVEL)) { - authRequestContext_->bindLevel = jsonObject[TAG_BIND_LEVEL].get(); - } + + authRequestContext_->bindLevel = GetIntFromJsonString(jsonObject, TAG_BIND_LEVEL, INVALID_TYPE); authRequestContext_->closeSessionDelaySeconds = 0; if (IsString(jsonObject, PARAM_CLOSE_SESSION_DELAY_SECONDS)) { std::string delaySecondsStr = jsonObject[PARAM_CLOSE_SESSION_DELAY_SECONDS].get(); -- Gitee From 005e6a90860afa7a9adcf412b2ea5f009958f5fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Thu, 13 Mar 2025 13:58:18 +0800 Subject: [PATCH 2/8] =?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: 史晓晓 --- common/src/dm_anonymous.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 3a206ec21..81dfc01d1 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -399,12 +399,12 @@ std::string GetSubStr(const std::string &rawStr, const std::string &separator, i int32_t GetIntFromJsonString(const nlohmann::json &jsonObj, const std::string &key, int32_t defVal) { if (!IsString(jsonObj, key)) { - LOGE("%{public}s is not string", key); + LOGE("%{public}s is not string", key.c_str()); return defVal; } - std::string retValStr = jsonObject[key].get(); + std::string retValStr = jsonObj[key].get(); if (!IsNumberString(retValStr)) { - LOGE("%{public}s is not number", key); + LOGE("%{public}s is not number", key.c_str()); return defVal; } return std::atoi(retValStr.c_str()); -- Gitee From 783f58de0d5f713c00cb1941d90b14bc063fcbd0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Thu, 13 Mar 2025 14:38:46 +0800 Subject: [PATCH 3/8] =?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: 史晓晓 --- services/implementation/src/authentication/dm_auth_manager.cpp | 2 -- 1 file changed, 2 deletions(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 23068ed8c..ef5a49f4e 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -219,7 +219,6 @@ int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra, const if (jsonObject.is_discarded() || jsonObject.find(TAG_BIND_LEVEL) == jsonObject.end()) { return DM_OK; } - int32_t bindLevel = GetIntFromJsonString(jsonObject, TAG_BIND_LEVEL, INVALID_TYPE); if (static_cast(bindLevel) > APP || bindLevel < INVALID_TYPE) { LOGE("bindlevel error %{public}d.", bindLevel); @@ -326,7 +325,6 @@ void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) if (IsString(jsonObject, APP_THUMBNAIL)) { authRequestContext_->appThumbnail = jsonObject[APP_THUMBNAIL].get(); } - authRequestContext_->bindLevel = GetIntFromJsonString(jsonObject, TAG_BIND_LEVEL, INVALID_TYPE); authRequestContext_->closeSessionDelaySeconds = 0; if (IsString(jsonObject, PARAM_CLOSE_SESSION_DELAY_SECONDS)) { -- Gitee From e4bbd29472f31bf82ca6e458188bf81acbfab356 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Thu, 13 Mar 2025 19:00:39 +0800 Subject: [PATCH 4/8] =?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: 史晓晓 --- common/include/dm_anonymous.h | 2 +- common/src/dm_anonymous.cpp | 8 ++++---- .../src/authentication/dm_auth_manager.cpp | 10 ++++++++-- 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/common/include/dm_anonymous.h b/common/include/dm_anonymous.h index 5c29722e9..f053e7228 100644 --- a/common/include/dm_anonymous.h +++ b/common/include/dm_anonymous.h @@ -102,7 +102,7 @@ bool IsValueExist(const std::multimap unorderedmap, const bool IsDmCommonNotifyEventValid(DmCommonNotifyEvent dmCommonNotifyEvent); std::string SafetyDump(const nlohmann::json &jsonObj); std::string GetSubStr(const std::string &rawStr, const std::string &separator, int32_t index); -int32_t GetIntFromJsonString(const nlohmann::json &jsonObj, const std::string &key, int32_t defVal = 0); +bool IsJsonValIntegerString(const nlohmann::json &jsonObj, const std::string &key); } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_ANONYMOUS_H diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index 81dfc01d1..82053fa80 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -396,18 +396,18 @@ std::string GetSubStr(const std::string &rawStr, const std::string &separator, i return ""; } -int32_t GetIntFromJsonString(const nlohmann::json &jsonObj, const std::string &key, int32_t defVal) +bool IsJsonValIntegerString(const nlohmann::json &jsonObj, const std::string &key) { if (!IsString(jsonObj, key)) { LOGE("%{public}s is not string", key.c_str()); - return defVal; + return false; } std::string retValStr = jsonObj[key].get(); if (!IsNumberString(retValStr)) { LOGE("%{public}s is not number", key.c_str()); - return defVal; + return false; } - return std::atoi(retValStr.c_str()); + return true; } } // namespace DistributedHardware } // namespace OHOS \ No newline at end of file diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index ef5a49f4e..47d3acd74 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -219,7 +219,11 @@ int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra, const if (jsonObject.is_discarded() || jsonObject.find(TAG_BIND_LEVEL) == jsonObject.end()) { return DM_OK; } - int32_t bindLevel = GetIntFromJsonString(jsonObject, TAG_BIND_LEVEL, INVALID_TYPE); + if (!IsJsonValIntegerString(jsonObject, TAG_BIND_LEVEL)) { + LOGE("TAG_BIND_LEVEL is not integer string."); + return ERR_DM_INPUT_PARA_INVALID; + } + int32_t bindLevel = std::atoi(jsonObject[TAG_BIND_LEVEL].get().c_str()); if (static_cast(bindLevel) > APP || bindLevel < INVALID_TYPE) { LOGE("bindlevel error %{public}d.", bindLevel); return ERR_DM_INPUT_PARA_INVALID; @@ -325,7 +329,9 @@ void DmAuthManager::ParseJsonObject(nlohmann::json jsonObject) if (IsString(jsonObject, APP_THUMBNAIL)) { authRequestContext_->appThumbnail = jsonObject[APP_THUMBNAIL].get(); } - authRequestContext_->bindLevel = GetIntFromJsonString(jsonObject, TAG_BIND_LEVEL, INVALID_TYPE); + if (IsJsonValIntegerString(jsonObject, TAG_BIND_LEVEL)) { + authRequestContext_->bindLevel = std::atoi(jsonObject[TAG_BIND_LEVEL].get().c_str()); + } authRequestContext_->closeSessionDelaySeconds = 0; if (IsString(jsonObject, PARAM_CLOSE_SESSION_DELAY_SECONDS)) { std::string delaySecondsStr = jsonObject[PARAM_CLOSE_SESSION_DELAY_SECONDS].get(); -- Gitee From 37db53d8c261e0ce33ccddc742d8eaa4d1aba138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Sat, 15 Mar 2025 12:05:15 +0800 Subject: [PATCH 5/8] =?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: 史晓晓 --- common/include/dm_anonymous.h | 2 +- common/src/dm_anonymous.cpp | 2 +- .../src/authentication/dm_auth_manager.cpp | 12 ++++++------ 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/common/include/dm_anonymous.h b/common/include/dm_anonymous.h index 3ad91be47..447e310d7 100644 --- a/common/include/dm_anonymous.h +++ b/common/include/dm_anonymous.h @@ -103,7 +103,7 @@ bool IsValueExist(const std::multimap unorderedmap, const bool IsDmCommonNotifyEventValid(DmCommonNotifyEvent dmCommonNotifyEvent); std::string SafetyDump(const JsonItemObject &jsonObj); std::string GetSubStr(const std::string &rawStr, const std::string &separator, int32_t index); -bool IsJsonValIntegerString(const nlohmann::json &jsonObj, const std::string &key); +bool IsJsonValIntegerString(const JsonItemObject &jsonObj, const std::string &key); } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_ANONYMOUS_H diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index da1114643..bc35e9f47 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -396,7 +396,7 @@ std::string GetSubStr(const std::string &rawStr, const std::string &separator, i return ""; } -bool IsJsonValIntegerString(const nlohmann::json &jsonObj, const std::string &key) +bool IsJsonValIntegerString(const JsonItemObject &jsonObj, const std::string &key) { if (!IsString(jsonObj, key)) { LOGE("%{public}s is not string", key.c_str()); diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 4f57da842..9c2a42d14 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -216,11 +216,11 @@ int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra, const return ERR_DM_INPUT_PARA_INVALID; } - if (jsonObject.IsDiscarded() || !jsonObject.Contains(TAG_BIND_LEVEL) || - !IsInt32(jsonObject, TAG_BIND_LEVEL)) { - return DM_OK; + if (!IsJsonValIntegerString(jsonObject, TAG_BIND_LEVEL)) { + LOGE("TAG_BIND_LEVEL is not integer string."); + return ERR_DM_INPUT_PARA_INVALID; } - int32_t bindLevel = jsonObject[TAG_BIND_LEVEL].Get(); + int32_t bindLevel = std::atoi(jsonObject[TAG_BIND_LEVEL].Get()); if (static_cast(bindLevel) > APP || bindLevel < INVALID_TYPE) { LOGE("bindlevel error %{public}d.", bindLevel); return ERR_DM_INPUT_PARA_INVALID; @@ -326,8 +326,8 @@ void DmAuthManager::ParseJsonObject(JsonObject &jsonObject) if (IsString(jsonObject, APP_THUMBNAIL)) { authRequestContext_->appThumbnail = jsonObject[APP_THUMBNAIL].Get(); } - if (IsInt32(jsonObject, TAG_BIND_LEVEL)) { - authRequestContext_->bindLevel = jsonObject[TAG_BIND_LEVEL].Get(); + if (IsJsonValIntegerString(jsonObject, TAG_BIND_LEVEL)) { + authRequestContext_->bindLevel = std::atoi(jsonObject[TAG_BIND_LEVEL].get().c_str()); } authRequestContext_->closeSessionDelaySeconds = 0; if (IsString(jsonObject, PARAM_CLOSE_SESSION_DELAY_SECONDS)) { -- Gitee From 0d33f0de0fd4df79dc7ba82d42ad3ed95b5f2c6a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Sat, 15 Mar 2025 12:08:44 +0800 Subject: [PATCH 6/8] =?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: 史晓晓 --- .../implementation/src/authentication/dm_auth_manager.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index 9c2a42d14..ef194d02e 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -215,7 +215,10 @@ int32_t DmAuthManager::CheckAuthParamVaildExtra(const std::string &extra, const LOGE("CONN_SESSION_TYPE_HML, CheckHmlParamValid failed"); return ERR_DM_INPUT_PARA_INVALID; } - + if (jsonObject.IsDiscarded() || !jsonObject.Contains(TAG_BIND_LEVEL) || + !IsString(jsonObject, TAG_BIND_LEVEL)) { + return DM_OK; + } if (!IsJsonValIntegerString(jsonObject, TAG_BIND_LEVEL)) { LOGE("TAG_BIND_LEVEL is not integer string."); return ERR_DM_INPUT_PARA_INVALID; -- Gitee From 45d79f91aeb7b0ec321a82cf91cf3fd000934c37 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Sat, 15 Mar 2025 12:11:49 +0800 Subject: [PATCH 7/8] =?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: 史晓晓 --- services/implementation/src/authentication/dm_auth_manager.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/services/implementation/src/authentication/dm_auth_manager.cpp b/services/implementation/src/authentication/dm_auth_manager.cpp index ef194d02e..00b4bc819 100644 --- a/services/implementation/src/authentication/dm_auth_manager.cpp +++ b/services/implementation/src/authentication/dm_auth_manager.cpp @@ -330,7 +330,7 @@ void DmAuthManager::ParseJsonObject(JsonObject &jsonObject) authRequestContext_->appThumbnail = jsonObject[APP_THUMBNAIL].Get(); } if (IsJsonValIntegerString(jsonObject, TAG_BIND_LEVEL)) { - authRequestContext_->bindLevel = std::atoi(jsonObject[TAG_BIND_LEVEL].get().c_str()); + authRequestContext_->bindLevel = std::atoi(jsonObject[TAG_BIND_LEVEL].Get()); } authRequestContext_->closeSessionDelaySeconds = 0; if (IsString(jsonObject, PARAM_CLOSE_SESSION_DELAY_SECONDS)) { -- Gitee From 8e8a10ab3ab993aec9a3af14e7e9edaea70f9468 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=8F=B2=E6=99=93=E6=99=93?= Date: Sat, 15 Mar 2025 15:25:38 +0800 Subject: [PATCH 8/8] =?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: 史晓晓 --- common/src/dm_anonymous.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/src/dm_anonymous.cpp b/common/src/dm_anonymous.cpp index bc35e9f47..0bf73567f 100644 --- a/common/src/dm_anonymous.cpp +++ b/common/src/dm_anonymous.cpp @@ -402,7 +402,7 @@ bool IsJsonValIntegerString(const JsonItemObject &jsonObj, const std::string &ke LOGE("%{public}s is not string", key.c_str()); return false; } - std::string retValStr = jsonObj[key].get(); + std::string retValStr = jsonObj[key].Get(); if (!IsNumberString(retValStr)) { LOGE("%{public}s is not number", key.c_str()); return false; -- Gitee