From 882f5b7d1b4a60c52f2ad3454444f879434268df Mon Sep 17 00:00:00 2001 From: Santiago Piccinini Date: Sun, 17 Jan 2021 18:59:48 -0300 Subject: [PATCH] stm32: cdcacm: fix array out of bounds write Remove debug leftovers that were causing memory corruption. Writes of 64 or more bytes from the USB host side caused memory corruption before this commit. I've tested it in a STM32L4 board and it is working as expected. --- examples/stm32/f1/lisa-m-1/usb_cdcacm/cdcacm.c | 1 - examples/stm32/f1/other/usb_cdcacm/cdcacm.c | 1 - examples/stm32/f1/stm32-h103/usb_cdcacm/cdcacm.c | 1 - examples/stm32/f1/stm32-maple/usb_cdcacm/cdcacm.c | 1 - examples/stm32/f1/waveshare-open103r/usbserial/usbserial.c | 1 - examples/stm32/f3/stm32f3-discovery/usb_cdcacm/cdcacm.c | 1 - 6 files changed, 6 deletions(-) diff --git a/examples/stm32/f1/lisa-m-1/usb_cdcacm/cdcacm.c b/examples/stm32/f1/lisa-m-1/usb_cdcacm/cdcacm.c index 9f6a133..496d367 100644 --- a/examples/stm32/f1/lisa-m-1/usb_cdcacm/cdcacm.c +++ b/examples/stm32/f1/lisa-m-1/usb_cdcacm/cdcacm.c @@ -213,7 +213,6 @@ static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) if (len) { while (usbd_ep_write_packet(usbd_dev, 0x82, buf, len) == 0) ; - buf[len] = 0; } gpio_toggle(GPIOC, GPIO5); diff --git a/examples/stm32/f1/other/usb_cdcacm/cdcacm.c b/examples/stm32/f1/other/usb_cdcacm/cdcacm.c index d63be7e..405ce96 100644 --- a/examples/stm32/f1/other/usb_cdcacm/cdcacm.c +++ b/examples/stm32/f1/other/usb_cdcacm/cdcacm.c @@ -212,7 +212,6 @@ static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) if (len) { usbd_ep_write_packet(usbd_dev, 0x82, buf, len); - buf[len] = 0; } } diff --git a/examples/stm32/f1/stm32-h103/usb_cdcacm/cdcacm.c b/examples/stm32/f1/stm32-h103/usb_cdcacm/cdcacm.c index 1f762e0..b46538d 100644 --- a/examples/stm32/f1/stm32-h103/usb_cdcacm/cdcacm.c +++ b/examples/stm32/f1/stm32-h103/usb_cdcacm/cdcacm.c @@ -212,7 +212,6 @@ static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) if (len) { usbd_ep_write_packet(usbd_dev, 0x82, buf, len); - buf[len] = 0; } } diff --git a/examples/stm32/f1/stm32-maple/usb_cdcacm/cdcacm.c b/examples/stm32/f1/stm32-maple/usb_cdcacm/cdcacm.c index 1dbf06a..a67ef00 100644 --- a/examples/stm32/f1/stm32-maple/usb_cdcacm/cdcacm.c +++ b/examples/stm32/f1/stm32-maple/usb_cdcacm/cdcacm.c @@ -213,7 +213,6 @@ static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) if (len) { usbd_ep_write_packet(usbd_dev, 0x82, buf, len); - buf[len] = 0; } } diff --git a/examples/stm32/f1/waveshare-open103r/usbserial/usbserial.c b/examples/stm32/f1/waveshare-open103r/usbserial/usbserial.c index 461752d..44639de 100644 --- a/examples/stm32/f1/waveshare-open103r/usbserial/usbserial.c +++ b/examples/stm32/f1/waveshare-open103r/usbserial/usbserial.c @@ -224,7 +224,6 @@ static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) if (len) { usbd_ep_write_packet(usbd_dev, 0x82, buf, len); - buf[len] = 0; } } diff --git a/examples/stm32/f3/stm32f3-discovery/usb_cdcacm/cdcacm.c b/examples/stm32/f3/stm32f3-discovery/usb_cdcacm/cdcacm.c index a94996b..bcdd79a 100644 --- a/examples/stm32/f3/stm32f3-discovery/usb_cdcacm/cdcacm.c +++ b/examples/stm32/f3/stm32f3-discovery/usb_cdcacm/cdcacm.c @@ -212,7 +212,6 @@ static void cdcacm_data_rx_cb(usbd_device *usbd_dev, uint8_t ep) if (len) { usbd_ep_write_packet(usbd_dev, 0x82, buf, len); - buf[len] = 0; } }