Skip to content

Commit afb307d

Browse files
jfischer-nonashif
authored andcommitted
usb: dfu: check requested length (wLength) during DFU_UPLOAD
During DFU_UPLOAD, the host could requests more data as stated in wTransferSize. Limit upload length to the size of the request buffer (USB_REQUEST_BUFFER_SIZE). Signed-off-by: Johann Fischer <[email protected]> Signed-off-by: David Brown <[email protected]>
1 parent c59db75 commit afb307d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

subsys/usb/class/usb_dfu.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -515,6 +515,15 @@ static int dfu_class_handle_req(struct usb_setup_packet *pSetup,
515515
len = pSetup->wLength;
516516
}
517517

518+
if (len > USB_DFU_MAX_XFER_SIZE) {
519+
/*
520+
* The host could requests more data as stated
521+
* in wTransferSize. Limit upload length to the
522+
* size of the request-buffer.
523+
*/
524+
len = USB_DFU_MAX_XFER_SIZE;
525+
}
526+
518527
if (len) {
519528
const struct flash_area *fa;
520529

0 commit comments

Comments
 (0)