]> sigrok.org Git - libsigrok.git/commitdiff
scpi_usbtmc_libusb: Check that bulk in requests read the entire header
authorAndy Lutomirski <redacted>
Sat, 13 Jun 2020 22:32:36 +0000 (15:32 -0700)
committerUwe Hermann <redacted>
Wed, 24 Jun 2020 22:03:24 +0000 (00:03 +0200)
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.

src/scpi/scpi_usbtmc_libusb.c

index d45d1f4c8f2b01876230fb1b3ba3814008546238..c8bcd0dc4e3e42cd389fc9a243096f1866c61a19 100644 (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.");