From cd25e1c01185f0d93a8f1b9b1d124d1c916e166d Mon Sep 17 00:00:00 2001 From: Koen Zandberg Date: Thu, 24 Oct 2019 11:51:07 +0200 Subject: [PATCH] usbus_fmt: assert descr len matches claimed len This commit adds runtime assertions to validate that the total length of the configuration descriptor as communicated to the host device matches the generated length of the configuration descriptor. --- sys/usb/usbus/usbus_fmt.c | 1 + 1 file changed, 1 insertion(+) diff --git a/sys/usb/usbus/usbus_fmt.c b/sys/usb/usbus/usbus_fmt.c index 223f1ce630..2e54fdbe41 100644 --- a/sys/usb/usbus/usbus_fmt.c +++ b/sys/usb/usbus/usbus_fmt.c @@ -260,6 +260,7 @@ size_t usbus_fmt_descriptor_conf(usbus_t *usbus) usbus_control_slicer_put_bytes(usbus, (uint8_t *)&conf, sizeof(conf)); len += _fmt_descriptors_post(usbus, usbus->descr_gen); len += _fmt_descriptors_ifaces(usbus); + assert(len == conf.total_length); return len; }