From 20005558967c1f6a73765c668bf2068a7903199d Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Mon, 11 Apr 2022 17:27:42 +0800 Subject: [PATCH 1/5] =?UTF-8?q?=E6=82=9F=E7=A9=BA=E6=B5=8B=E8=AF=95-?= =?UTF-8?q?=E9=98=B2=E6=AD=A2stoi=E5=BC=82=E5=B8=B8=20Signed-off-by:=20wan?= =?UTF-8?q?gyb0625=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kits/js/include/native_devicemanager_js.h | 2 ++ .../kits/js/src/native_devicemanager_js.cpp | 36 +++++++++++++++++++ 2 files changed, 38 insertions(+) diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h index 77a6f6abd..16881e10d 100644 --- a/interfaces/kits/js/include/native_devicemanager_js.h +++ b/interfaces/kits/js/include/native_devicemanager_js.h @@ -18,6 +18,7 @@ #include #include +#include #include "device_manager_callback.h" #include "dm_app_image_info.h" @@ -247,6 +248,7 @@ public: static void DeviceInfoToJsArray(const napi_env &env, const std::vector &vecDevInfo, const int32_t idx, napi_value &arrayResult); + static bool IsNumberString(const std::string &authToken); static void DmAuthParamToJsAuthParam(const napi_env &env, const OHOS::DistributedHardware::DmAuthParam &authParam, napi_value ¶mResult); static void SetValueInt32(const napi_env &env, const std::string &fieldStr, const int32_t intValue, diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 01503e91d..40f1a47d9 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -585,9 +585,45 @@ void DeviceManagerNapi::DeviceInfoToJsArray(const napi_env &env, const std::vect } } +bool DeviceManagerNapi::IsNumberString(const std::string &authToken) +{ + LOGI("IsNumberString for DeviceManagerNapi"); + for (int i = 0; i < authToken.size(); i++) + { + int tmp = (int)authToken[i]; + if (tmp >= 48 && tmp <= 57) + { + continue; + } + else + { + return false; + } + } + return true; +} + void DeviceManagerNapi::DmAuthParamToJsAuthParam(const napi_env &env, const DmAuthParam &authParam, napi_value ¶mResult) { + LOGI("DeviceManagerNapi::DmAuthParamToJsAuthParam"); + const uint32_t maxIntValuelen = 10; + const std::string maxAuthToken = "2147483647"; + if (authParam.authToken.length() > maxIntValuelen) { + LOGE("The authToken is illegal"); + return; + } else { + if (!IsNumberString(authParam.authToken)) { + LOGE("The authToken is Error"); + return; + } else { + if (authParam.authToken > maxAuthToken) { + LOGE("The authToken is Cross the border"); + return; + } + } + } + napi_value extraInfo = nullptr; napi_create_object(env, &extraInfo); SetValueInt32(env, "direction", authParam.direction, extraInfo); -- Gitee From 9a22bc0434cdb5d0355a18b37b0ff62a7a3b3548 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Tue, 12 Apr 2022 09:40:41 +0800 Subject: [PATCH 2/5] =?UTF-8?q?=E6=82=9F=E7=A9=BA=E6=B5=8B=E8=AF=95-?= =?UTF-8?q?=E9=98=B2=E6=AD=A2stoi=E5=BC=82=E5=B8=B8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: wangyb0625 --- .../kits/js/include/native_devicemanager_js.h | 3 +-- .../kits/js/src/native_devicemanager_js.cpp | 20 +----------------- utils/include/dm_anonymous.h | 2 ++ utils/src/dm_anonymous.cpp | 21 +++++++++++++++++++ 4 files changed, 25 insertions(+), 21 deletions(-) diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h index 16881e10d..0b9fd8ab7 100644 --- a/interfaces/kits/js/include/native_devicemanager_js.h +++ b/interfaces/kits/js/include/native_devicemanager_js.h @@ -18,7 +18,6 @@ #include #include -#include #include "device_manager_callback.h" #include "dm_app_image_info.h" @@ -29,6 +28,7 @@ #include "napi/native_node_api.h" #include "nlohmann/json.hpp" #define DM_NAPI_BUF_LENGTH (256) +#include "dm_anonymous.h" struct AsyncCallbackInfo { napi_env env = nullptr; @@ -248,7 +248,6 @@ public: static void DeviceInfoToJsArray(const napi_env &env, const std::vector &vecDevInfo, const int32_t idx, napi_value &arrayResult); - static bool IsNumberString(const std::string &authToken); static void DmAuthParamToJsAuthParam(const napi_env &env, const OHOS::DistributedHardware::DmAuthParam &authParam, napi_value ¶mResult); static void SetValueInt32(const napi_env &env, const std::string &fieldStr, const int32_t intValue, diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 40f1a47d9..ef340c852 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -585,24 +585,6 @@ void DeviceManagerNapi::DeviceInfoToJsArray(const napi_env &env, const std::vect } } -bool DeviceManagerNapi::IsNumberString(const std::string &authToken) -{ - LOGI("IsNumberString for DeviceManagerNapi"); - for (int i = 0; i < authToken.size(); i++) - { - int tmp = (int)authToken[i]; - if (tmp >= 48 && tmp <= 57) - { - continue; - } - else - { - return false; - } - } - return true; -} - void DeviceManagerNapi::DmAuthParamToJsAuthParam(const napi_env &env, const DmAuthParam &authParam, napi_value ¶mResult) { @@ -611,7 +593,7 @@ void DeviceManagerNapi::DmAuthParamToJsAuthParam(const napi_env &env, const DmAu const std::string maxAuthToken = "2147483647"; if (authParam.authToken.length() > maxIntValuelen) { LOGE("The authToken is illegal"); - return; + return; } else { if (!IsNumberString(authParam.authToken)) { LOGE("The authToken is Error"); diff --git a/utils/include/dm_anonymous.h b/utils/include/dm_anonymous.h index 3537598b8..99489326c 100644 --- a/utils/include/dm_anonymous.h +++ b/utils/include/dm_anonymous.h @@ -17,11 +17,13 @@ #define OHOS_DM_ANONYMOUS_H #include +#include namespace OHOS { namespace DistributedHardware { std::string GetAnonyString(const std::string &value); std::string GetAnonyInt32(const int32_t value); +bool IsNumberString(const std::string &authToken); } // namespace DistributedHardware } // namespace OHOS #endif // OHOS_DM_ANONYMOUS_H diff --git a/utils/src/dm_anonymous.cpp b/utils/src/dm_anonymous.cpp index 3c642541b..4f4ec7b33 100644 --- a/utils/src/dm_anonymous.cpp +++ b/utils/src/dm_anonymous.cpp @@ -56,5 +56,26 @@ std::string GetAnonyInt32(const int32_t value) } return tempString; } + +bool IsNumberString(const std::string &inputString) +{ + LOGI("IsNumberString for DeviceManagerNapi"); + if (inputString.length() == 0) { + LOGE("inputString is Null"); + return false; + } + const int32_t MIN_ASCLL_NUM = 48; + const int32_t MAX_ASCLL_NUM = 57; + for (int i = 0; i < inputString.length(); i++) { + int num = (int)inputString[i]; + if (num >= MIN_ASCLL_NUM && num <= MAX_ASCLL_NUM) { + continue; + } + else { + return false; + } + } + return true; +} } // namespace DistributedHardware } // namespace OHOS -- Gitee From 0b664a217680241ed627b99e395da22b00a88d5c Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Tue, 12 Apr 2022 10:44:34 +0800 Subject: [PATCH 3/5] codecheck Signed-off-by: wangyb0625 --- utils/include/dm_anonymous.h | 1 - utils/src/dm_anonymous.cpp | 5 ++--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/utils/include/dm_anonymous.h b/utils/include/dm_anonymous.h index 99489326c..16d476612 100644 --- a/utils/include/dm_anonymous.h +++ b/utils/include/dm_anonymous.h @@ -17,7 +17,6 @@ #define OHOS_DM_ANONYMOUS_H #include -#include namespace OHOS { namespace DistributedHardware { diff --git a/utils/src/dm_anonymous.cpp b/utils/src/dm_anonymous.cpp index 4f4ec7b33..91d0ca04d 100644 --- a/utils/src/dm_anonymous.cpp +++ b/utils/src/dm_anonymous.cpp @@ -70,11 +70,10 @@ bool IsNumberString(const std::string &inputString) int num = (int)inputString[i]; if (num >= MIN_ASCLL_NUM && num <= MAX_ASCLL_NUM) { continue; - } - else { + } else { return false; } - } + } return true; } } // namespace DistributedHardware -- Gitee From 069b0cea508c2fb3bb073959fd7eb55966832001 Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Tue, 12 Apr 2022 16:18:16 +0800 Subject: [PATCH 4/5] =?UTF-8?q?=E6=82=9F=E7=A9=BA=E6=B5=8B=E8=AF=95-?= =?UTF-8?q?=E9=98=B2=E6=AD=A2stoi=E5=BC=82=E5=B8=B8=20Signed-off-by:=20wan?= =?UTF-8?q?gyb0625=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../kits/js/include/native_devicemanager_js.h | 3 ++- .../kits/js/src/native_devicemanager_js.cpp | 26 +++++++++++++------ utils/include/dm_anonymous.h | 1 + 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/interfaces/kits/js/include/native_devicemanager_js.h b/interfaces/kits/js/include/native_devicemanager_js.h index 0b9fd8ab7..8db0b6022 100644 --- a/interfaces/kits/js/include/native_devicemanager_js.h +++ b/interfaces/kits/js/include/native_devicemanager_js.h @@ -24,11 +24,11 @@ #include "dm_device_info.h" #include "dm_native_event.h" #include "dm_subscribe_info.h" +#include "dm_anonymous.h" #include "napi/native_api.h" #include "napi/native_node_api.h" #include "nlohmann/json.hpp" #define DM_NAPI_BUF_LENGTH (256) -#include "dm_anonymous.h" struct AsyncCallbackInfo { napi_env env = nullptr; @@ -248,6 +248,7 @@ public: static void DeviceInfoToJsArray(const napi_env &env, const std::vector &vecDevInfo, const int32_t idx, napi_value &arrayResult); + static bool DmAuthParamDetection(const OHOS::DistributedHardware::DmAuthParam &authParam); static void DmAuthParamToJsAuthParam(const napi_env &env, const OHOS::DistributedHardware::DmAuthParam &authParam, napi_value ¶mResult); static void SetValueInt32(const napi_env &env, const std::string &fieldStr, const int32_t intValue, diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index ef340c852..772568167 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -585,26 +585,36 @@ void DeviceManagerNapi::DeviceInfoToJsArray(const napi_env &env, const std::vect } } -void DeviceManagerNapi::DmAuthParamToJsAuthParam(const napi_env &env, const DmAuthParam &authParam, - napi_value ¶mResult) +bool DeviceManagerNapi::DmAuthParamDetection(const DmAuthParam &authParam) { - LOGI("DeviceManagerNapi::DmAuthParamToJsAuthParam"); - const uint32_t maxIntValuelen = 10; + LOGI("DeviceManagerNapi::DmAuthParamDetection"); + const uint32_t maxIntValueLen = 10; const std::string maxAuthToken = "2147483647"; - if (authParam.authToken.length() > maxIntValuelen) { + if (authParam.authToken.length() > maxIntValueLen) { LOGE("The authToken is illegal"); - return; + return false; } else { if (!IsNumberString(authParam.authToken)) { LOGE("The authToken is Error"); - return; + return false; } else { if (authParam.authToken > maxAuthToken) { LOGE("The authToken is Cross the border"); - return; + return false; } } } + return true; +} + +void DeviceManagerNapi::DmAuthParamToJsAuthParam(const napi_env &env, const DmAuthParam &authParam, + napi_value ¶mResult) +{ + LOGI("DeviceManagerNapi::DmAuthParamToJsAuthParam"); + if (!DmAuthParamDetection(authParam)) { + LOGE("The authToken is Error"); + return; + } napi_value extraInfo = nullptr; napi_create_object(env, &extraInfo); diff --git a/utils/include/dm_anonymous.h b/utils/include/dm_anonymous.h index 16d476612..47523eb72 100644 --- a/utils/include/dm_anonymous.h +++ b/utils/include/dm_anonymous.h @@ -17,6 +17,7 @@ #define OHOS_DM_ANONYMOUS_H #include +#include "dm_log.h" namespace OHOS { namespace DistributedHardware { -- Gitee From 0b007fcf83d70edf055e9f7af1c78afc26c3a28e Mon Sep 17 00:00:00 2001 From: wangyb0625 Date: Tue, 12 Apr 2022 17:24:33 +0800 Subject: [PATCH 5/5] =?UTF-8?q?=E4=BF=AE=E6=94=B9codecheck=20Signed-off-by?= =?UTF-8?q?:=20wangyb0625=20?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- interfaces/kits/js/src/native_devicemanager_js.cpp | 2 +- utils/include/dm_anonymous.h | 1 - utils/src/dm_anonymous.cpp | 1 + 3 files changed, 2 insertions(+), 2 deletions(-) diff --git a/interfaces/kits/js/src/native_devicemanager_js.cpp b/interfaces/kits/js/src/native_devicemanager_js.cpp index 772568167..6f9c57510 100644 --- a/interfaces/kits/js/src/native_devicemanager_js.cpp +++ b/interfaces/kits/js/src/native_devicemanager_js.cpp @@ -592,7 +592,7 @@ bool DeviceManagerNapi::DmAuthParamDetection(const DmAuthParam &authParam) const std::string maxAuthToken = "2147483647"; if (authParam.authToken.length() > maxIntValueLen) { LOGE("The authToken is illegal"); - return false; + return false; } else { if (!IsNumberString(authParam.authToken)) { LOGE("The authToken is Error"); diff --git a/utils/include/dm_anonymous.h b/utils/include/dm_anonymous.h index 47523eb72..16d476612 100644 --- a/utils/include/dm_anonymous.h +++ b/utils/include/dm_anonymous.h @@ -17,7 +17,6 @@ #define OHOS_DM_ANONYMOUS_H #include -#include "dm_log.h" namespace OHOS { namespace DistributedHardware { diff --git a/utils/src/dm_anonymous.cpp b/utils/src/dm_anonymous.cpp index 91d0ca04d..12ce168e1 100644 --- a/utils/src/dm_anonymous.cpp +++ b/utils/src/dm_anonymous.cpp @@ -14,6 +14,7 @@ */ #include "dm_anonymous.h" +#include "dm_log.h" namespace OHOS { namespace DistributedHardware { -- Gitee