summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavid Khan <[email protected]>2026-07-02 21:49:32 +0530
committerJavid Khan <[email protected]>2026-07-02 21:49:32 +0530
commit8a2d00f330f9150d0d08cacb6382406eebef692a (patch)
tree39dcfaa0802ec24ab4f86210f24a3584668e0daf
parent7a4111b96ef6279e75579f9a18443834f6a0871d (diff)
bound cdc-data endpoints against descriptor length in acm_open
-rw-r--r--src/class/cdc/cdc_host.c6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c
index 30afc2f5c..902316029 100644
--- a/src/class/cdc/cdc_host.c
+++ b/src/class/cdc/cdc_host.c
@@ -1031,6 +1031,7 @@ static uint16_t acm_open(uint8_t daddr, const tusb_desc_interface_t *itf_desc, u
// Open notification endpoint of control interface if any
if (itf_desc->bNumEndpoints == 1) {
+ TU_ASSERT(tu_desc_in_bounds(p_desc, desc_end), 0);
TU_ASSERT(TUSB_DESC_ENDPOINT == tu_desc_type(p_desc), 0);
const tusb_desc_endpoint_t *desc_ep = (const tusb_desc_endpoint_t *)p_desc;
TU_ASSERT(tuh_edpt_open(daddr, desc_ep), 0);
@@ -1040,12 +1041,13 @@ static uint16_t acm_open(uint8_t daddr, const tusb_desc_interface_t *itf_desc, u
}
//------------- Data Interface (if any) -------------//
- if (TUSB_DESC_INTERFACE == tu_desc_type(p_desc)) {
+ if (tu_desc_in_bounds(p_desc, desc_end) && TUSB_DESC_INTERFACE == tu_desc_type(p_desc)) {
const tusb_desc_interface_t *data_itf = (const tusb_desc_interface_t *)p_desc;
if (data_itf->bInterfaceClass == TUSB_CLASS_CDC_DATA) {
p_desc = tu_desc_next(p_desc); // next to endpoint descriptor
- // data endpoints expected to be in pairs
+ // data endpoints expected to be in pairs, make sure both fit before reading them
+ TU_ASSERT((uint16_t)(desc_end - p_desc) >= 2 * sizeof(tusb_desc_endpoint_t), 0);
TU_ASSERT(open_ep_stream_pair(p_cdc, (const tusb_desc_endpoint_t *)p_desc), 0);
p_desc += data_itf->bNumEndpoints * sizeof(tusb_desc_endpoint_t);
}