From 2d5c08a83776703da455ca5bdcdf0ab97864bde6 Mon Sep 17 00:00:00 2001 From: akallabeth Date: Thu, 9 Jul 2020 12:20:48 +0200 Subject: [PATCH] Fixed invalid buffer length and duplicated write function. (cherry picked from commit 54c92e78e6031d1e075625699e2d677af583716a) --- channels/urbdrc/client/data_transfer.c | 4 +--- channels/urbdrc/client/libusb/libusb_udevice.c | 5 ++++- channels/urbdrc/common/urbdrc_helpers.c | 4 ++-- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/channels/urbdrc/client/data_transfer.c b/channels/urbdrc/client/data_transfer.c index fe6768c..d67c33c 100644 --- a/channels/urbdrc/client/data_transfer.c +++ b/channels/urbdrc/client/data_transfer.c @@ -765,9 +765,7 @@ static void urb_isoch_transfer_cb(IUDEVICE* pdev, URBDRC_CHANNEL_CALLBACK* callb Stream_Write_UINT32(out, OutputBufferSize); /** OutputBufferSize */ Stream_Seek(out, OutputBufferSize); - if (!pdev->isChannelClosed(pdev)) - callback->channel->Write(callback->channel, Stream_GetPosition(out), Stream_Buffer(out), - NULL); + stream_write_and_free(callback->plugin, callback->channel, out); } } diff --git a/channels/urbdrc/client/libusb/libusb_udevice.c b/channels/urbdrc/client/libusb/libusb_udevice.c index 0332e28..85e15ff 100644 --- a/channels/urbdrc/client/libusb/libusb_udevice.c +++ b/channels/urbdrc/client/libusb/libusb_udevice.c @@ -924,7 +924,10 @@ static int libusb_udev_os_feature_descriptor_request(IUDEVICE* idev, UINT32 Requ LIBUSB_ENDPOINT_IN | LIBUSB_REQUEST_TYPE_VENDOR | Recipient, bMS_Vendorcode, (InterfaceNumber << 8) | Ms_PageIndex, Ms_featureDescIndex, Buffer, *BufferSize, Timeout); - *BufferSize = error; + log_libusb_result(pdev->urbdrc->log, WLOG_DEBUG, "libusb_control_transfer", error); + + if (error >= 0) + *BufferSize = error; } if (error < 0) diff --git a/channels/urbdrc/common/urbdrc_helpers.c b/channels/urbdrc/common/urbdrc_helpers.c index 80d6149..53c3b89 100644 --- a/channels/urbdrc/common/urbdrc_helpers.c +++ b/channels/urbdrc/common/urbdrc_helpers.c @@ -391,7 +391,7 @@ void urbdrc_dump_message(wLog* log, BOOL client, BOOL write, wStream* s) pos = Stream_GetPosition(s); if (write) { - length = Stream_GetPosition(s); + length = pos; Stream_SetPosition(s, 0); } else @@ -407,7 +407,7 @@ void urbdrc_dump_message(wLog* log, BOOL client, BOOL write, wStream* s) WLog_Print(log, WLOG_DEBUG, "[%-5s] %s [%08" PRIx32 "] InterfaceId=%08" PRIx32 ", MessageId=%08" PRIx32 - ", FunctionId=%08" PRIx32 ", length=%" PRIdz, + ", FunctionId=%08" PRIx32 ", length=%" PRIuz, type, call_to_string(client, InterfaceId, FunctionId), FunctionId, InterfaceId, MessageId, FunctionId, length); #if defined(WITH_DEBUG_URBDRC) -- 2.7.4