scpi_usbtmc_libusb: Check that bulk in requests read the entire header

The Rigol DS1054Z sometimes returns zero bytes in response to a bulk in
request.  sigrok ends up reading out of bounds and failing ungracefully
when this happens.  Check that libusb returned a full USBTMC header and
fail gracefully if it did not.
This commit is contained in:
Andy Lutomirski 2020-06-13 15:32:36 -07:00 committed by Uwe Hermann
parent 6999029585
commit e2283318c1
1 changed files with 5 additions and 0 deletions

View File

@ -534,6 +534,11 @@ static int scpi_usbtmc_bulkin_start(struct scpi_usbtmc_libusb *uscpi,
return SR_ERR;
}
if (transferred < USBTMC_BULK_HEADER_SIZE) {
sr_err("USBTMC bulk in returned too little data: %d/%d bytes\n", transferred, size);
return SR_ERR;
}
if (usbtmc_bulk_in_header_read(data, msg_id, uscpi->bTag, &message_size,
transfer_attributes) != SR_OK) {
sr_err("USBTMC invalid bulk in header.");