~ruther/stm32h747i-disco-usb-image-viewer

a9ffd7282525bfe771b156f3ea8c56ab25939f6e — Rutherther 5 months ago c3eb05f
fix: make sure to error if endpoint id not found in interrupt

This generally shouldn't happen,
but it needs to be ensured that the
memory at incorrect place won't be read
or written to!
Otherwise there could be undefined behavior!
This would possibly write to the fifos,
meaning the data the usb sends could be
different than what the application intended!
1 files changed, 12 insertions(+), 0 deletions(-)

M src/usb_device.c
M src/usb_device.c => src/usb_device.c +12 -0
@@ 392,6 392,12 @@ uint8_t usb_daint_get_endpoint_number(uint32_t endpoints) {

void usb_handle_endpoint_in_int(usb_device_t* device) {
  uint8_t ep_id = usb_daint_get_endpoint_number(reg_read_bits_pos(&device->device->DAINT, USB_OTG_DAINT_IEPINT_Pos, 0xFFFF));

  if (ep_id == 0xFF) {
    device->state = ERROR;
    return;
  }

  uint32_t interrupt_reg = device->in[ep_id].DIEPINT;

  if (interrupt_reg & USB_OTG_DIEPINT_PKTDRPSTS) {


@@ 447,6 453,12 @@ void usb_handle_endpoint_out_int(usb_device_t* device) {
  /* device->core->GRXFSIZ; */

  uint8_t ep_id = usb_daint_get_endpoint_number(reg_read_bits_pos(&device->device->DAINT, USB_OTG_DAINT_OEPINT_Pos, 0xFFFF));

  if (ep_id == 0xFF) {
    device->state = ERROR;
    return;
  }

  uint32_t interrupt_reg = device->out[ep_id].DOEPINT;

  if (interrupt_reg & USB_OTG_DOEPINT_STPKTRX) {

Do not follow this link