소스 검색

update(hub/usbh_hub): add check for nports

Signed-off-by: sakumisu <1203593632@qq.com>
sakumisu 3 달 전
부모
커밋
ec82b8a36c
1개의 변경된 파일5개의 추가작업 그리고 0개의 파일을 삭제
  1. 5 0
      class/hub/usbh_hub.c

+ 5 - 0
class/hub/usbh_hub.c

@@ -387,6 +387,11 @@ static int usbh_hub_connect(struct usbh_hubport *hport, uint8_t intf)
         hub->tt_think = ((hub->hub_desc.wHubCharacteristics & HUB_CHAR_TTTT_MASK) >> 5);
     }
 
+    if (hub->nports > CONFIG_USBHOST_MAX_EHPORTS) {
+        USB_LOG_ERR("Hub nports %u overflow\r\n", hub->nports);
+        return -USB_ERR_NOMEM;
+    }
+
     for (uint8_t port = 0; port < hub->nports; port++) {
         hub->child[port].port = port + 1;
         hub->child[port].parent = hub;