diff options
author | Pete Batard <pbatard@gmail.com> | 2010-10-13 22:34:57 +0100 |
---|---|---|
committer | Pete Batard <pbatard@gmail.com> | 2010-10-13 22:34:57 +0100 |
commit | 7b7157d5bae3020abef965693963bd9a3fe16511 (patch) | |
tree | b45a2aa1e8bf1c4673fef88d753e9d2466c732c7 /libusb | |
parent | 501f1e1a06427361f8ddddffda1f19701bc454e9 (diff) | |
download | libusb-7b7157d5bae3020abef965693963bd9a3fe16511.tar.gz |
fixed trac #68 (incorrect buffer size for HID reports)pbr313
* this regression was introduced in pbr301
* reported by gorlik
Diffstat (limited to 'libusb')
-rw-r--r-- | libusb/libusb_version.h | 2 | ||||
-rw-r--r-- | libusb/os/windows_usb.c | 17 |
2 files changed, 7 insertions, 12 deletions
diff --git a/libusb/libusb_version.h b/libusb/libusb_version.h index b3bee2b..151e963 100644 --- a/libusb/libusb_version.h +++ b/libusb/libusb_version.h @@ -24,6 +24,6 @@ #define LIBUSB_VERSION_MAJOR 1 #define LIBUSB_VERSION_MINOR 0 #define LIBUSB_VERSION_MICRO 8 -#define LIBUSB_VERSION_NANO 10312 +#define LIBUSB_VERSION_NANO 10313 #endif diff --git a/libusb/os/windows_usb.c b/libusb/os/windows_usb.c index 8842ebf..dbea297 100644 --- a/libusb/os/windows_usb.c +++ b/libusb/os/windows_usb.c @@ -3237,11 +3237,6 @@ static int _hid_get_report(struct hid_device_priv* dev, HANDLE hid_handle, int i return LIBUSB_ERROR_INVALID_PARAM; } - // When report IDs are not in use, add an extra byte for the report ID - if (id==0) { - expected_size++; - } - // Add a trailing byte to detect overflows buf = (uint8_t*)calloc(expected_size+1, 1); if (buf == NULL) { @@ -3251,7 +3246,9 @@ static int _hid_get_report(struct hid_device_priv* dev, HANDLE hid_handle, int i usbi_dbg("report ID: 0x%02X", buf[0]); tp->hid_expected_size = expected_size; + read_size = expected_size; + // NB: The size returned by DeviceIoControl doesn't include report IDs when not in use (0) if (!DeviceIoControl(hid_handle, ioctl_code, buf, expected_size+1, buf, expected_size+1, &read_size, overlapped)) { if (GetLastError() != ERROR_IO_PENDING) { @@ -3267,7 +3264,7 @@ static int _hid_get_report(struct hid_device_priv* dev, HANDLE hid_handle, int i // Transfer completed synchronously => copy and discard extra buffer if (read_size == 0) { - usbi_dbg("program assertion failed - read completed synchronously, but no data was read"); + usbi_warn(NULL, "program assertion failed - read completed synchronously, but no data was read"); *size = 0; } else { if (buf[0] != id) { @@ -3280,12 +3277,11 @@ static int _hid_get_report(struct hid_device_priv* dev, HANDLE hid_handle, int i r = LIBUSB_COMPLETED; } + *size = MIN((size_t)read_size, *size); if (id == 0) { // Discard report ID - *size = MIN((size_t)read_size-1, *size); memcpy(data, buf+1, *size); } else { - *size = MIN((size_t)read_size, *size); memcpy(data, buf, *size); } } @@ -3343,6 +3339,7 @@ static int _hid_set_report(struct hid_device_priv* dev, HANDLE hid_handle, int i } } + // NB: The size returned by DeviceIoControl doesn't include report IDs when not in use (0) if (!DeviceIoControl(hid_handle, ioctl_code, buf, write_size, buf, write_size, &write_size, overlapped)) { if (GetLastError() != ERROR_IO_PENDING) { @@ -3356,11 +3353,9 @@ static int _hid_set_report(struct hid_device_priv* dev, HANDLE hid_handle, int i } // Transfer completed synchronously + *size = write_size; if (write_size == 0) { usbi_dbg("program assertion failed - write completed synchronously, but no data was written"); - *size = 0; - } else { - *size = write_size - ((id == 0)?1:0); } safe_free(buf); return LIBUSB_COMPLETED; |