From fab1f95f44bfac5fcc4c8db9aa180c26c4926ba2 Mon Sep 17 00:00:00 2001 From: lijianhua38 Date: Wed, 14 Jun 2023 16:19:17 +0800 Subject: [PATCH] =?UTF-8?q?Wifi-sethostspotconfig=E5=8F=82=E6=95=B0?= =?UTF-8?q?=E4=B8=BAnull,=E8=BF=94=E5=9B=9E=E6=88=90=E5=8A=9F=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: lijianhua38 --- wifi/frameworks/js/napi/src/wifi_napi_hotspot.cpp | 4 +++- wifi/frameworks/js/napi/src/wifi_napi_utils.cpp | 12 +++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/wifi/frameworks/js/napi/src/wifi_napi_hotspot.cpp b/wifi/frameworks/js/napi/src/wifi_napi_hotspot.cpp index e6d9414f2..bc35bec5a 100644 --- a/wifi/frameworks/js/napi/src/wifi_napi_hotspot.cpp +++ b/wifi/frameworks/js/napi/src/wifi_napi_hotspot.cpp @@ -129,7 +129,9 @@ static bool GetHotspotconfigFromJs(const napi_env& env, const napi_value& object config.SetChannel(AP_CHANNEL_5G_DEFAULT); } value = 0; - JsObjectToString(env, object, "preSharedKey", NAPI_MAX_STR_LENT, str); // 64: max length + if (!JsObjectToString(env, object, "preSharedKey", NAPI_MAX_STR_LENT, str)) { // 64: max length + return false; + } ClearJsLastException(env); config.SetPreSharedKey(str); JsObjectToInt(env, object, "maxConn", value); diff --git a/wifi/frameworks/js/napi/src/wifi_napi_utils.cpp b/wifi/frameworks/js/napi/src/wifi_napi_utils.cpp index 9e4e2acc2..6a3165133 100644 --- a/wifi/frameworks/js/napi/src/wifi_napi_utils.cpp +++ b/wifi/frameworks/js/napi/src/wifi_napi_utils.cpp @@ -68,14 +68,17 @@ napi_value JsObjectToString(const napi_env& env, const napi_value& object, napi_get_named_property(env, object, fieldStr, &field); NAPI_CALL(env, napi_typeof(env, field, &valueType)); - NAPI_ASSERT(env, valueType == napi_string, "Wrong argument type. String expected."); + if (valueType != napi_string) { + WIFI_LOGE("Wrong argument type. String expected."); + return NULL; + } if (bufLen <= 0) { - goto error; + return NULL; } char *buf = (char *)malloc(bufLen); if (buf == nullptr) { WIFI_LOGE("Js object to str malloc failed"); - goto error; + return NULL; } (void)memset_s(buf, bufLen, 0, bufLen); size_t result = 0; @@ -90,9 +93,8 @@ napi_value JsObjectToString(const napi_env& env, const napi_value& object, buf = nullptr; } else { WIFI_LOGW("Js obj to str no property: %{public}s", fieldStr); + return NULL; } - -error: return UndefinedNapiValue(env); }