From ce95f656adcda701888c7414d2ab0f88f3f2c0ae Mon Sep 17 00:00:00 2001 From: Chris Dickens Date: Tue, 28 Jan 2020 10:24:14 -0800 Subject: Windows: Fix reported length of synchronous control transfers WinUSB control transfers that complete synchronously are incorrectly having the actual transfer length set to the size of the transfer buffer. If the control transfer is a read, the device may return less data than the transfer buffer size. Fix this by reporting the actual bytes transferred. Closes #667 Signed-off-by: Chris Dickens --- libusb/os/windows_winusb.c | 6 +++--- libusb/version_nano.h | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libusb/os/windows_winusb.c b/libusb/os/windows_winusb.c index 136abb2..7cb17be 100644 --- a/libusb/os/windows_winusb.c +++ b/libusb/os/windows_winusb.c @@ -2472,7 +2472,7 @@ static int winusbx_submit_control_transfer(int sub_api, struct usbi_transfer *it struct winusb_transfer_priv *transfer_priv = usbi_transfer_get_os_priv(itransfer); struct winusb_device_handle_priv *handle_priv = _device_handle_priv(transfer->dev_handle); PWINUSB_SETUP_PACKET setup = (PWINUSB_SETUP_PACKET)transfer->buffer; - ULONG size; + ULONG size, transferred; HANDLE winusb_handle; OVERLAPPED *overlapped; int current_interface; @@ -2510,13 +2510,13 @@ static int winusbx_submit_control_transfer(int sub_api, struct usbi_transfer *it } windows_force_sync_completion(overlapped, 0); } else { - if (!WinUSBX[sub_api].ControlTransfer(winusb_handle, *setup, transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE, size, NULL, overlapped)) { + if (!WinUSBX[sub_api].ControlTransfer(winusb_handle, *setup, transfer->buffer + LIBUSB_CONTROL_SETUP_SIZE, size, &transferred, overlapped)) { if (GetLastError() != ERROR_IO_PENDING) { usbi_warn(ctx, "ControlTransfer failed: %s", windows_error_str(0)); return LIBUSB_ERROR_IO; } } else { - windows_force_sync_completion(overlapped, size); + windows_force_sync_completion(overlapped, transferred); } } diff --git a/libusb/version_nano.h b/libusb/version_nano.h index 9cef97f..18c8cb7 100644 --- a/libusb/version_nano.h +++ b/libusb/version_nano.h @@ -1 +1 @@ -#define LIBUSB_NANO 11451 +#define LIBUSB_NANO 11452 -- cgit v1.2.1