已合并
check napi return value #11402
wangJE创建于 2025年12月30日
check napi return value #11402
已合并
共 3 个文件变更+12-4
| @@ -33,8 +33,6 @@ | |||
| 33 | #include "securec.h" | 33 | #include "securec.h" |
| 34 | #include "softbus_adapter_mem.h" | 34 | #include "softbus_adapter_mem.h" |
| 35 | 35 | ||
| 36 | -#define SOFTBUS_NAME_MAX_LEN 255 | ||
| 37 | - | ||
| 38 | namespace Communication { | 36 | namespace Communication { |
| 39 | namespace OHOS::Softbus { | 37 | namespace OHOS::Softbus { |
| 40 | 38 | ||
| @@ -52,7 +52,7 @@ static napi_status CheckCreateConnectionParams(napi_env env, napi_callback_info | |||
| 52 | return napi_string_expected; | 52 | return napi_string_expected; |
| 53 | } | 53 | } |
| 54 | 54 | ||
| 55 | - if (deviceId.length() == 0 || name.length() == 0 || name.length() > SOFTBUS_NAME_MAX_LEN) { | 55 | + if (deviceId.length() == 0 || name.length() == 0) { |
| 56 | COMM_LOGE(COMM_SDK, "name or deviceId is null"); | 56 | COMM_LOGE(COMM_SDK, "name or deviceId is null"); |
| 57 | return napi_invalid_arg; | 57 | return napi_invalid_arg; |
| 58 | } | 58 | } |
| @@ -320,6 +320,11 @@ napi_value NapiLinkEnhanceConnection::Connect(napi_env env, napi_callback_info i | |||
| 320 | if (handle <= 0) { | 320 | if (handle <= 0) { |
| 321 | COMM_LOGE(COMM_SDK, "connect fail, err=%{public}d", handle); | 321 | COMM_LOGE(COMM_SDK, "connect fail, err=%{public}d", handle); |
| 322 | int32_t errcode = ConvertToJsErrcode(handle); | 322 | int32_t errcode = ConvertToJsErrcode(handle); |
| 323 | + if (errcode == LINK_ENHANCE_PARAMETER_INVALID) { | ||
| 324 | + napi_throw_error(env, std::to_string(errcode).c_str(), | ||
| 325 | + "check whether the length of the name input when calling the createConnection interface is valid"); | ||
| 326 | + return NapiGetUndefinedRet(env); | ||
| 327 | + } | ||
| 323 | HandleSyncErr(env, errcode); | 328 | HandleSyncErr(env, errcode); |
| 324 | return NapiGetUndefinedRet(env); | 329 | return NapiGetUndefinedRet(env); |
| 325 | } | 330 | } |
| @@ -41,7 +41,7 @@ static napi_status CheckCreateServerParams(napi_env env, napi_callback_info info | |||
| 41 | COMM_LOGE(COMM_SDK, "unexpect string"); | 41 | COMM_LOGE(COMM_SDK, "unexpect string"); |
| 42 | return napi_string_expected; | 42 | return napi_string_expected; |
| 43 | } | 43 | } |
| 44 | - if (name.length() == 0 || name.length() > SOFTBUS_NAME_MAX_LEN) { | 44 | + if (name.length() == 0) { |
| 45 | COMM_LOGE(COMM_SDK, "invalid name"); | 45 | COMM_LOGE(COMM_SDK, "invalid name"); |
| 46 | return napi_invalid_arg; | 46 | return napi_invalid_arg; |
| 47 | } | 47 | } |
| @@ -284,6 +284,11 @@ napi_value NapiLinkEnhanceServer::Start(napi_env env, napi_callback_info info) | |||
| 284 | if (ret != 0) { | 284 | if (ret != 0) { |
| 285 | COMM_LOGE(COMM_SDK, "create server fail, ret=%{public}d", ret); | 285 | COMM_LOGE(COMM_SDK, "create server fail, ret=%{public}d", ret); |
| 286 | int32_t errCode = ConvertToJsErrcode(ret); | 286 | int32_t errCode = ConvertToJsErrcode(ret); |
| 287 | + if (errCode == LINK_ENHANCE_PARAMETER_INVALID) { | ||
| 288 | + napi_throw_error(env, std::to_string(errCode).c_str(), | ||
| 289 | + "check whether the length of the name input when calling the createServer interface is valid"); | ||
| 290 | + return NapiGetUndefinedRet(env); | ||
| 291 | + } | ||
| 287 | HandleSyncErr(env, errCode); | 292 | HandleSyncErr(env, errCode); |
| 288 | } | 293 | } |
| 289 | return NapiGetUndefinedRet(env); | 294 | return NapiGetUndefinedRet(env); |