summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJavid Khan <[email protected]>2026-07-05 16:26:13 +0530
committerJavid Khan <[email protected]>2026-07-05 16:26:31 +0530
commiteebd0c1c1c04d68a56eac09f56ed16e0ee570a0d (patch)
tree3ae17ccac3ac8400c02516721a1b27de727e87d7
parentea39a8f4b12e2fc572931d7da4f3025589c536e7 (diff)
bound acm_open functional descriptor walk against desc_end
-rw-r--r--src/class/cdc/cdc_host.c7
1 files changed, 5 insertions, 2 deletions
diff --git a/src/class/cdc/cdc_host.c b/src/class/cdc/cdc_host.c
index aeaab1c21..6045350a8 100644
--- a/src/class/cdc/cdc_host.c
+++ b/src/class/cdc/cdc_host.c
@@ -1022,8 +1022,11 @@ static uint16_t acm_open(uint8_t daddr, const tusb_desc_interface_t *itf_desc, u
p_desc = tu_desc_next(p_desc);
// Communication Functional Descriptors
- while ((p_desc < desc_end) && (TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc))) {
- if (CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT == cdc_functional_desc_typeof(p_desc)) {
+ // need the 3-byte header (bLength/bDescriptorType/bDescriptorSubType) in bounds before reading it, and a
+ // bLength >= 3 both keeps those reads valid and stops a zero-length descriptor from spinning the walk
+ while (p_desc + 3 <= desc_end && TUSB_DESC_CS_INTERFACE == tu_desc_type(p_desc) && tu_desc_len(p_desc) >= 3) {
+ if (CDC_FUNC_DESC_ABSTRACT_CONTROL_MANAGEMENT == cdc_functional_desc_typeof(p_desc) &&
+ p_desc + sizeof(cdc_desc_func_acm_t) <= desc_end) {
// save ACM bmCapabilities
p_cdc->acm.capability = ((cdc_desc_func_acm_t const *) p_desc)->bmCapabilities;
}