diff --git a/interfaces/kits/js/napi/src/napi_util.cpp b/interfaces/kits/js/napi/src/napi_util.cpp index 523497381db432b16ff892859d4eb6a9af0a5035..acf15c9d8406b3143402b4c78769471bf408494f 100644 --- a/interfaces/kits/js/napi/src/napi_util.cpp +++ b/interfaces/kits/js/napi/src/napi_util.cpp @@ -1,5 +1,5 @@ /* - * Copyright (C) 2021-2022 Huawei Device Co., Ltd. + * Copyright (C) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -160,17 +160,10 @@ bool NapiUtil::JsUint8ArrayParse( USB_HILOGW(MODULE_JS_NAPI, "get typedarray info failed, status: %{public}d", infoStatus); return false; } - - if (type != napi_uint8_array) { - USB_HILOGW(MODULE_JS_NAPI, "not Uint8Array type: %{public}d", type); - return false; - } - - if (bufferSize == 0) { - USB_HILOGW(MODULE_JS_NAPI, "bufferSize error"); - return false; - } - + USB_ASSERT_RETURN_FALSE( + env, type == napi_uint8_array, SYSPARAM_INVALID_INPUT, "The type of buffer must be Uint8Array."); + USB_ASSERT_RETURN_FALSE( + env, bufferSize != 0, SYSPARAM_INVALID_INPUT, "The size of buffer must be a positive number."); return true; } diff --git a/interfaces/kits/js/napi/src/usb_info.cpp b/interfaces/kits/js/napi/src/usb_info.cpp index 3e00776607881d90203ec9bc41a59d6ce2aadaeb..caa33b6256889dc58feb6d68417bbe625fcf73c0 100644 --- a/interfaces/kits/js/napi/src/usb_info.cpp +++ b/interfaces/kits/js/napi/src/usb_info.cpp @@ -1,5 +1,5 @@ /* - * Copyright (c) 2021-2022 Huawei Device Co., Ltd. + * Copyright (c) 2021-2023 Huawei Device Co., Ltd. * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at @@ -1080,7 +1080,13 @@ static std::tuple GetControlTran // timeOut param int32_t timeOut = 0; - if (argc >= PARAM_COUNT_3) { + if (argc > PARAM_COUNT_2) { + napi_typeof(env, argv[INDEX_2], &type); + if (type != napi_number) { + USB_HILOGE(MODULE_JS_NAPI, "index 2 wrong argument type, number expected."); + ThrowBusinessError(env, SYSPARAM_INVALID_INPUT, "The type of timeOut must be positive number."); + return {false, {}, {}, {}}; + } napi_get_value_int32(env, argv[INDEX_2], &timeOut); } @@ -1212,6 +1218,9 @@ static bool GetBulkTransferParams(napi_env env, napi_callback_info info, USBBulk int32_t timeOut = 0; if (argc > PARAM_COUNT_3) { + napi_typeof(env, argv[INDEX_3], &type); + USB_ASSERT_RETURN_FALSE( + env, type == napi_number, SYSPARAM_INVALID_INPUT, "The type of timeOut must be number."); napi_get_value_int32(env, argv[INDEX_3], &timeOut); }