When extracting transfer data, pay attention to the size of the buffer

provided by the user, which may be smaller than the length of data
received in the transfer.
This commit is contained in:
Sebastian Zagrodzki
2017-02-08 22:37:12 +01:00
parent a19ac0f654
commit a35725f4fb

View File

@@ -74,8 +74,8 @@ int extract_data(struct libusb_transfer *xfer, void *raw, int max, unsigned char
// Copy the data
int len = pkt.actual_length;
if (len > max) {
len = max;
if (copied + len > max) {
len = max - copied;
}
memcpy(out, in, len);
copied += len;
@@ -84,10 +84,14 @@ int extract_data(struct libusb_transfer *xfer, void *raw, int max, unsigned char
in += pkt.length;
out += len;
if (copied == max) {
break;
}
// Extract first error
if (pkt.status == 0 || *status != 0) {
continue;
}
}
*status = pkt.status;
}
return copied;