Commit 49ae610bf4d8e98265e9b4326bb7adc537f7ba2a

Con Kolivas 2013-11-22T10:24:35

Don't lose data beyond the end of message in a usb read.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
diff --git a/usbutils.c b/usbutils.c
index ee8e713..fe6f8f4 100644
--- a/usbutils.c
+++ b/usbutils.c
@@ -2612,8 +2612,12 @@ int _usb_read(struct cgpu_info *cgpu, int intinfo, int epinfo, char *buf, size_t
 	/* If we found the end of message marker, just use that data and
 	 * return success. */
 	if (eom) {
-		tot = (void *)eom - (void *)usbbuf + endlen;
-		err = LIBUSB_SUCCESS;
+		size_t eomlen = (void *)eom - (void *)usbbuf + endlen;
+
+		if (eomlen < bufsiz) {
+			bufsiz = eomlen;
+			err = LIBUSB_SUCCESS;
+		}
 	}
 
 	// N.B. usbdev->buffer was emptied before the while() loop