usb: Prevent memcpy() being called with NULL arguments
If there is no additional iface data then iface->extra is NULL and iface->extralen is zero. Passing NULL to memcpy is undefined behaviour even if the length of data to copy is zero. In other words a conforming (debug) memcpy implementation is permitted to assert(dst && src) without checking the value of n. Add an extra branch to avoid this.
This commit is contained in:
parent
342ec6e9e3
commit
0b63408260
@ -93,12 +93,14 @@ static uint16_t build_config_descriptor(usbd_device *usbd_dev,
|
|||||||
total += count;
|
total += count;
|
||||||
totallen += iface->bLength;
|
totallen += iface->bLength;
|
||||||
/* Copy extra bytes (function descriptors). */
|
/* Copy extra bytes (function descriptors). */
|
||||||
memcpy(buf, iface->extra,
|
if (iface->extra) {
|
||||||
count = MIN(len, iface->extralen));
|
memcpy(buf, iface->extra,
|
||||||
buf += count;
|
count = MIN(len, iface->extralen));
|
||||||
len -= count;
|
buf += count;
|
||||||
total += count;
|
len -= count;
|
||||||
totallen += iface->extralen;
|
total += count;
|
||||||
|
totallen += iface->extralen;
|
||||||
|
}
|
||||||
/* For each endpoint... */
|
/* For each endpoint... */
|
||||||
for (k = 0; k < iface->bNumEndpoints; k++) {
|
for (k = 0; k < iface->bNumEndpoints; k++) {
|
||||||
const struct usb_endpoint_descriptor *ep =
|
const struct usb_endpoint_descriptor *ep =
|
||||||
|
Loading…
x
Reference in New Issue
Block a user