From 6b95ec72efcc159b4f31dc0259ded4895db7fdef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E9=99=85=E7=BA=A2?= Date: Thu, 15 Aug 2024 01:23:22 +0000 Subject: [PATCH 1/4] fix napi param verifying MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 秦际红 --- interfaces/kits/js/napi/include/napi_util.h | 1 + interfaces/kits/js/napi/src/napi_util.cpp | 18 ++++++ interfaces/kits/js/napi/src/usb_info.cpp | 69 +++++++++++++++------ 3 files changed, 68 insertions(+), 20 deletions(-) diff --git a/interfaces/kits/js/napi/include/napi_util.h b/interfaces/kits/js/napi/include/napi_util.h index 3cbdd61d..dae66b31 100644 --- a/interfaces/kits/js/napi/include/napi_util.h +++ b/interfaces/kits/js/napi/include/napi_util.h @@ -28,6 +28,7 @@ public: const int32_t bufLen, std::string &fieldRef); static bool JsObjectGetProperty( const napi_env &env, const napi_value &object, std::string fieldStr, napi_value &value); + static void JsObjectToBool(const napi_env &env, const napi_value &object, std::string fieldStr, bool &fieldRef); static void JsObjectToInt(const napi_env &env, const napi_value &object, std::string fieldStr, int32_t &fieldRef); static void JsObjectToUint( const napi_env &env, const napi_value &object, const std::string &fieldStr, uint32_t &fieldRef); diff --git a/interfaces/kits/js/napi/src/napi_util.cpp b/interfaces/kits/js/napi/src/napi_util.cpp index 8fb26282..e3e90ece 100644 --- a/interfaces/kits/js/napi/src/napi_util.cpp +++ b/interfaces/kits/js/napi/src/napi_util.cpp @@ -91,6 +91,24 @@ bool NapiUtil::JsObjectGetProperty( return hasProperty; } +void NapiUtil::JsObjectToBool(const napi_env &env, const napi_value &object, std::string fieldStr, bool &fieldRef) +{ + bool hasProperty = false; + napi_has_named_property(env, object, fieldStr.c_str(), &hasProperty); + if (hasProperty) { + napi_value field; + napi_valuetype valueType; + + napi_get_named_property(env, object, fieldStr.c_str(), &field); + napi_typeof(env, field, &valueType); + USB_ASSERT_RETURN_VOID( + env, valueType == napi_boolean, SYSPARAM_INVALID_INPUT, "The type of " + fieldStr + " must be boolean."); + napi_get_value_bool(env, field, &fieldRef); + } else { + USB_HILOGW(MODULE_JS_NAPI, "js to boolean no property: %{public}s", fieldStr.c_str()); + } +} + void NapiUtil::JsObjectToInt(const napi_env &env, const napi_value &object, std::string fieldStr, int32_t &fieldRef) { bool hasProperty = false; diff --git a/interfaces/kits/js/napi/src/usb_info.cpp b/interfaces/kits/js/napi/src/usb_info.cpp index dcfce6b3..fe860613 100644 --- a/interfaces/kits/js/napi/src/usb_info.cpp +++ b/interfaces/kits/js/napi/src/usb_info.cpp @@ -187,6 +187,14 @@ static void ParseEndpointObj(const napi_env env, const napi_value endpointObj, U NapiUtil::JsObjectToInt(env, endpointObj, "interval", interval); int32_t maxPacketSize = 0; NapiUtil::JsObjectToInt(env, endpointObj, "maxPacketSize", maxPacketSize); + int32_t direction = 0; + NapiUtil::JsObjectToInt(env, endpointObj, "direction", direction); + USB_ASSERT_RETURN_VOID(env, (direction == USB_ENDPOINT_DIR_IN || direction == USB_ENDPOINT_DIR_OUT), + SYSPARAM_INVALID_INPUT, "The interface should have the endpoints property."); + int32_t number = 0; + NapiUtil::JsObjectToInt(env, endpointObj, "number", number); + int32_t type = 0; + NapiUtil::JsObjectToInt(env, endpointObj, "type", type); int32_t interfaceId = 0; NapiUtil::JsObjectToInt(env, endpointObj, "interfaceId", interfaceId); ep = USBEndpoint(address, attributes, interval, maxPacketSize); @@ -363,6 +371,10 @@ static void ParseConfigObj(const napi_env env, const napi_value configObj, USBCo NapiUtil::JsObjectToInt(env, configObj, "maxPower", maxPower); std::string name; NapiUtil::JsObjectToString(env, configObj, "name", DEFAULT_DESCRIPTION_SIZE, name); + bool isRemoteWakeup = false; + NapiUtil::JsObjectToBool(env, configObj, "isRemoteWakeup", isRemoteWakeup); + bool isSelfPowered = false; + NapiUtil::JsObjectToBool(env, configObj, "isSelfPowered", isSelfPowered); std::vector interfaces; bool ret = ParseInterfacesObjs(env, configObj, interfaces); @@ -406,6 +418,8 @@ static void ParseDeviceObj(const napi_env env, const napi_value deviceObj, UsbDe NapiUtil::JsObjectToString(env, deviceObj, "productName", DEFAULT_DESCRIPTION_SIZE, productName); std::string version; NapiUtil::JsObjectToString(env, deviceObj, "version", DEFAULT_DESCRIPTION_SIZE, version); + std::string serial; + NapiUtil::JsObjectToString(env, deviceObj, "serial", DEFAULT_DESCRIPTION_SIZE, serial); int32_t devAddr = 0; NapiUtil::JsObjectToInt(env, deviceObj, "devAddress", devAddr); int32_t busNum = 0; @@ -463,7 +477,7 @@ static napi_value CoreConnectDevice(napi_env env, napi_callback_info info) size_t argc = PARAM_COUNT_1; napi_value argv[PARAM_COUNT_1] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function takes one argument."); + USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function at least takes one argument."); napi_value deviceObj = argv[INDEX_0]; napi_valuetype type; @@ -491,7 +505,7 @@ static napi_value DeviceAddRight(napi_env env, napi_callback_info info) size_t argc = PARAM_COUNT_2; napi_value argv[PARAM_COUNT_2] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_2), SYSPARAM_INVALID_INPUT, "The function takes two argument."); + USB_ASSERT(env, (argc >= PARAM_COUNT_2), SYSPARAM_INVALID_INPUT, "The function at least takes two argument."); napi_valuetype type; NAPI_CHECK(env, napi_typeof(env, argv[INDEX_0], &type), "Get args 1 type failed"); @@ -521,7 +535,7 @@ static napi_value DeviceAddAccessRight(napi_env env, napi_callback_info info) size_t argc = PARAM_COUNT_2; napi_value argv[PARAM_COUNT_2] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_2), SYSPARAM_INVALID_INPUT, "The function takes two argument."); + USB_ASSERT(env, (argc >= PARAM_COUNT_2), SYSPARAM_INVALID_INPUT, "The function at least takes two argument."); napi_valuetype type; NAPI_CHECK(env, napi_typeof(env, argv[INDEX_0], &type), "Get args 1 type failed"); @@ -551,7 +565,7 @@ static napi_value DeviceRemoveRight(napi_env env, napi_callback_info info) size_t argc = PARAM_COUNT_1; napi_value argv[PARAM_COUNT_1] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function takes one argument."); + USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function at least takes one argument."); napi_valuetype type; NAPI_CHECK(env, napi_typeof(env, argv[INDEX_0], &type), "Get args 1 type failed"); @@ -576,7 +590,7 @@ static napi_value CoreHasRight(napi_env env, napi_callback_info info) size_t argc = PARAM_COUNT_1; napi_value args[PARAM_COUNT_1] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function takes one argument."); + USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function at least takes one argument."); napi_valuetype type; NAPI_CHECK(env, napi_typeof(env, args[INDEX_0], &type), "Get args 1 type failed"); @@ -620,7 +634,7 @@ static napi_value CoreRequestRight(napi_env env, napi_callback_info info) size_t argc = PARAM_COUNT_1; napi_value args[PARAM_COUNT_1] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function takes one argument."); + USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function at least takes one argument."); napi_valuetype type; NAPI_CHECK(env, napi_typeof(env, args[INDEX_0], &type), "Get args 1 type failed"); @@ -656,7 +670,7 @@ static napi_value CoreUsbFunctionsFromString(napi_env env, napi_callback_info in napi_value argv[PARAM_COUNT_1] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function takes one argument."); + USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function at least takes one argument."); napi_valuetype type; NAPI_CHECK(env, napi_typeof(env, argv[INDEX_0], &type), "Get args 1 type failed"); @@ -682,7 +696,7 @@ static napi_value CoreUsbFunctionsToString(napi_env env, napi_callback_info info napi_value argv[PARAM_COUNT_1] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function takes one argument."); + USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function at least takes one argument."); napi_valuetype type; NAPI_CHECK(env, napi_typeof(env, argv[INDEX_0], &type), "Get args 1 type failed"); @@ -732,7 +746,7 @@ static napi_value CoreSetCurrentFunctions(napi_env env, napi_callback_info info) napi_value argv[PARAM_COUNT_1] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function takes one argument."); + USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function at least takes one argument."); napi_valuetype type; NAPI_CHECK(env, napi_typeof(env, argv[INDEX_0], &type), "Get args 1 type failed"); @@ -830,7 +844,7 @@ static napi_value PortGetSupportedModes(napi_env env, napi_callback_info info) napi_value args[PARAM_COUNT_1] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function takes one argument."); + USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function at least takes one argument."); napi_valuetype type; NAPI_CHECK(env, napi_typeof(env, args[INDEX_0], &type), "Get args 1 type failed"); @@ -886,7 +900,7 @@ static napi_value PortSetPortRole(napi_env env, napi_callback_info info) napi_value args[PARAM_COUNT_3] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, args, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_3), SYSPARAM_INVALID_INPUT, "The function takes three arguments."); + USB_ASSERT(env, (argc >= PARAM_COUNT_3), SYSPARAM_INVALID_INPUT, "The function at least takes three arguments."); napi_valuetype type; NAPI_CHECK(env, napi_typeof(env, args[INDEX_0], &type), "Get args 1 type failed"); @@ -974,7 +988,7 @@ static napi_value PipeReleaseInterface(napi_env env, napi_callback_info info) napi_value argv[PARAM_COUNT_2] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_2), SYSPARAM_INVALID_INPUT, "The function takes two arguments."); + USB_ASSERT(env, (argc >= PARAM_COUNT_2), SYSPARAM_INVALID_INPUT, "The function at least takes two arguments."); napi_value obj = argv[INDEX_0]; napi_valuetype type; @@ -1002,7 +1016,7 @@ static napi_value PipeSetInterface(napi_env env, napi_callback_info info) size_t argc = PARAM_COUNT_2; napi_value argv[PARAM_COUNT_2] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_2), SYSPARAM_INVALID_INPUT, "The function takes two arguments."); + USB_ASSERT(env, (argc >= PARAM_COUNT_2), SYSPARAM_INVALID_INPUT, "The function at least takes two arguments."); napi_value pipeObj = argv[INDEX_0]; napi_valuetype type; @@ -1030,7 +1044,7 @@ static napi_value PipeSetConfiguration(napi_env env, napi_callback_info info) size_t argc = PARAM_COUNT_2; napi_value argv[PARAM_COUNT_2] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_2), SYSPARAM_INVALID_INPUT, "The function takes two arguments."); + USB_ASSERT(env, (argc >= PARAM_COUNT_2), SYSPARAM_INVALID_INPUT, "The function at least takes two arguments."); napi_valuetype type; napi_value pipeObj = argv[INDEX_0]; @@ -1059,7 +1073,7 @@ static napi_value PipeGetRawDescriptors(napi_env env, napi_callback_info info) napi_value argv[PARAM_COUNT_1] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function takes one argument."); + USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function at least takes one argument."); napi_value obj = argv[INDEX_0]; napi_valuetype type; napi_typeof(env, obj, &type); @@ -1086,7 +1100,7 @@ static napi_value PipeGetFileDescriptor(napi_env env, napi_callback_info info) napi_value argv[PARAM_COUNT_1] = {nullptr}; NAPI_CHECK(env, napi_get_cb_info(env, info, &argc, argv, nullptr, nullptr), "Get call back info failed"); - USB_ASSERT(env, (argc == PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function takes one argument."); + USB_ASSERT(env, (argc >= PARAM_COUNT_1), SYSPARAM_INVALID_INPUT, "The function at least takes one argument."); napi_value obj = argv[INDEX_0]; napi_valuetype type; napi_typeof(env, obj, &type); @@ -1145,7 +1159,9 @@ static auto g_controlTransferComplete = [](napi_env env, napi_status status, voi USB_HILOGD(MODULE_JS_NAPI, "ControlTransfer failed"); napi_create_int32(env, -1, &queryResult); } - ProcessPromise(env, *asyncContext, queryResult); + if (asyncContext->deferred) { + napi_resolve_deferred(env, asyncContext->deferred, queryResult); + } napi_delete_async_work(env, asyncContext->work); delete asyncContext; }; @@ -1300,7 +1316,9 @@ static auto g_usbControlTransferComplete = [](napi_env env, napi_status status, USB_HILOGD(MODULE_JS_NAPI, "usbControlTransfer failed"); napi_create_int32(env, -1, &queryResult); } - ProcessPromise(env, *asyncContext, queryResult); + if (asyncContext->deferred) { + napi_resolve_deferred(env, asyncContext->deferred, queryResult); + } napi_delete_async_work(env, asyncContext->work); delete asyncContext; }; @@ -1335,6 +1353,13 @@ static std::tuple GetUsbContr ParseUsbDevicePipe(env, argv[INDEX_0], pipe); // control params + napi_typeof(env, argv[INDEX_1], &type); + if (type != napi_object) { + USB_HILOGE(MODULE_JS_NAPI, "index 1 wrong argument type, object expected."); + ThrowBusinessError(env, SYSPARAM_INVALID_INPUT, "The type of pipe must be USBDeviceRequestParams."); + return {false, {}, {}, {}}; + } + UsbPipeControlParam controlParam = {0}; ParseUsbPipeControlParam(env, argv[INDEX_1], controlParam); @@ -1449,7 +1474,9 @@ static auto g_bulkTransferComplete = [](napi_env env, napi_status status, void * USB_HILOGE(MODULE_JS_NAPI, "BulkTransfer failed"); napi_create_int32(env, -1, &queryResult); } - ProcessPromise(env, *asyncContext, queryResult); + if (asyncContext->deferred) { + napi_resolve_deferred(env, asyncContext->deferred, queryResult); + } napi_delete_async_work(env, asyncContext->work); delete asyncContext; }; @@ -1543,7 +1570,9 @@ static napi_value PipeBulkTransfer(napi_env env, napi_callback_info info) asyncContext->status = napi_invalid_arg; napi_value queryResult = nullptr; napi_create_int32(env, -1, &queryResult); - ProcessPromise(env, *asyncContext, queryResult); + if (asyncContext->deferred) { + napi_resolve_deferred(env, asyncContext->deferred, queryResult); + } delete asyncContext; return result; } -- Gitee From 63d25f6b8897297f2c0d7ff1d0426d4850d32a15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E9=99=85=E7=BA=A2?= Date: Thu, 15 Aug 2024 01:26:39 +0000 Subject: [PATCH 2/4] add for nullptr verifying MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 秦际红 --- interfaces/kits/js/napi/src/usb_info.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/napi/src/usb_info.cpp b/interfaces/kits/js/napi/src/usb_info.cpp index fe860613..f6299ad9 100644 --- a/interfaces/kits/js/napi/src/usb_info.cpp +++ b/interfaces/kits/js/napi/src/usb_info.cpp @@ -1277,7 +1277,7 @@ static napi_value PipeControlTransfer(napi_env env, napi_callback_info info) static auto g_usbControlTransferExecute = [](napi_env env, void *data) { USBDeviceControlTransferAsyncContext *asyncContext = (USBDeviceControlTransferAsyncContext *)data; std::vector bufferData(asyncContext->buffer, asyncContext->buffer + asyncContext->bufferLength); - if ((asyncContext->reqType & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_DIR_OUT) { + if ((asyncContext->reqType & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_DIR_OUT || asyncContext->buffer != nullptr) { delete[] asyncContext->buffer; asyncContext->buffer = nullptr; } -- Gitee From 6e55f8b57d636539204cd5517e057b2b14ec24f4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E9=99=85=E7=BA=A2?= Date: Thu, 15 Aug 2024 11:08:10 +0000 Subject: [PATCH 3/4] fix manageInterface test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 秦际红 --- .../service_unittest/src/usb_manage_interface_test.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/native/service_unittest/src/usb_manage_interface_test.cpp b/test/native/service_unittest/src/usb_manage_interface_test.cpp index 1bdfa781..1256f1de 100644 --- a/test/native/service_unittest/src/usb_manage_interface_test.cpp +++ b/test/native/service_unittest/src/usb_manage_interface_test.cpp @@ -195,7 +195,7 @@ HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType001, TestSize.Level1) UsbDeviceType usbDeviceType; usbDeviceType.baseClass = 3; usbDeviceType.subClass = 1; - usbDeviceType.protocal = 2; + usbDeviceType.protocol = 2; usbDeviceType.isDeviceType = 0; disableType.emplace_back(usbDeviceType); ret = client.ManageInterfaceType(disableType, true); @@ -214,7 +214,7 @@ HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType002, TestSize.Level1) UsbDeviceType usbDeviceType; usbDeviceType.baseClass = 8; usbDeviceType.subClass = 6; - usbDeviceType.protocal = 80; + usbDeviceType.protocol = 80; usbDeviceType.isDeviceType = 0; disableType.emplace_back(usbDeviceType); ret = client.ManageInterfaceType(disableType, true); @@ -233,7 +233,7 @@ HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType003, TestSize.Level1) UsbDeviceType usbDeviceType; usbDeviceType.baseClass = 3; usbDeviceType.subClass = 1; - usbDeviceType.protocal = 2; + usbDeviceType.protocol = 2; usbDeviceType.isDeviceType = 0; disableType.emplace_back(usbDeviceType); ret = client.ManageInterfaceType(disableType, false); @@ -252,7 +252,7 @@ HWTEST_F(UsbManageInterfaceTest, ManageInterfaceType004, TestSize.Level1) UsbDeviceType usbDeviceType; usbDeviceType.baseClass = 8; usbDeviceType.subClass = 6; - usbDeviceType.protocal = 80; + usbDeviceType.protocol = 80; usbDeviceType.isDeviceType = 0; disableType.emplace_back(usbDeviceType); ret = client.ManageInterfaceType(disableType, false); -- Gitee From d2fa940ce63bd833ddc22665d4861d140933d221 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=A7=A6=E9=99=85=E7=BA=A2?= Date: Thu, 15 Aug 2024 13:12:02 +0000 Subject: [PATCH 4/4] fix logic err MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 秦际红 --- interfaces/kits/js/napi/src/usb_info.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/interfaces/kits/js/napi/src/usb_info.cpp b/interfaces/kits/js/napi/src/usb_info.cpp index f6299ad9..564deaf2 100644 --- a/interfaces/kits/js/napi/src/usb_info.cpp +++ b/interfaces/kits/js/napi/src/usb_info.cpp @@ -1277,7 +1277,7 @@ static napi_value PipeControlTransfer(napi_env env, napi_callback_info info) static auto g_usbControlTransferExecute = [](napi_env env, void *data) { USBDeviceControlTransferAsyncContext *asyncContext = (USBDeviceControlTransferAsyncContext *)data; std::vector bufferData(asyncContext->buffer, asyncContext->buffer + asyncContext->bufferLength); - if ((asyncContext->reqType & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_DIR_OUT || asyncContext->buffer != nullptr) { + if ((asyncContext->reqType & USB_ENDPOINT_DIR_MASK) == USB_ENDPOINT_DIR_OUT && asyncContext->buffer != nullptr) { delete[] asyncContext->buffer; asyncContext->buffer = nullptr; } -- Gitee