Windows: Fix reported length of synchronous control transfers
authorChris Dickens <christopher.a.dickens@gmail.com>
Tue, 28 Jan 2020 18:24:14 +0000 (10:24 -0800)
committerChris Dickens <christopher.a.dickens@gmail.com>
Tue, 28 Jan 2020 18:24:14 +0000 (10:24 -0800)
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 <christopher.a.dickens@gmail.com>
libusb/os/windows_winusb.c
libusb/version_nano.h

index 136abb2..7cb17be 100644 (file)
@@ -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);
                }
        }
 
index 9cef97f..18c8cb7 100644 (file)
@@ -1 +1 @@
-#define LIBUSB_NANO 11451
+#define LIBUSB_NANO 11452