Merge branch 'fix/usb_short_desc' into 'master'

fix(usb/host): Do not abort on string descriptor overflow

See merge request espressif/esp-idf!27127
This commit is contained in:
Tomas Rezucha
2023-11-21 10:22:03 +08:00
2 changed files with 10 additions and 4 deletions

View File

@@ -449,10 +449,17 @@ static bool enum_stage_transfer_check(enum_ctrl_t *enum_ctrl)
return false; return false;
} }
// Check IN transfer returned the expected correct number of bytes // Check IN transfer returned the expected correct number of bytes
if (enum_ctrl->expect_num_bytes != 0 && enum_ctrl->expect_num_bytes != transfer->actual_num_bytes) { if (enum_ctrl->expect_num_bytes != 0 && transfer->actual_num_bytes != enum_ctrl->expect_num_bytes) {
if (transfer->actual_num_bytes > enum_ctrl->expect_num_bytes) {
// The device returned more bytes than requested.
// This violates the USB specs chapter 9.3.5, but we can continue
ESP_LOGW(HUB_DRIVER_TAG, "Incorrect number of bytes returned %d: %s", transfer->actual_num_bytes, enum_stage_strings[enum_ctrl->stage]);
} else {
// The device returned less bytes than requested. We cannot continue.
ESP_LOGE(HUB_DRIVER_TAG, "Incorrect number of bytes returned %d: %s", transfer->actual_num_bytes, enum_stage_strings[enum_ctrl->stage]); ESP_LOGE(HUB_DRIVER_TAG, "Incorrect number of bytes returned %d: %s", transfer->actual_num_bytes, enum_stage_strings[enum_ctrl->stage]);
return false; return false;
} }
}
// Stage specific checks and updates // Stage specific checks and updates
bool ret; bool ret;

View File

@@ -74,7 +74,6 @@ static void action_get_info(class_driver_t *driver_obj)
ESP_ERROR_CHECK(usb_host_device_info(driver_obj->dev_hdl, &dev_info)); ESP_ERROR_CHECK(usb_host_device_info(driver_obj->dev_hdl, &dev_info));
ESP_LOGI(TAG, "\t%s speed", (dev_info.speed == USB_SPEED_LOW) ? "Low" : "Full"); ESP_LOGI(TAG, "\t%s speed", (dev_info.speed == USB_SPEED_LOW) ? "Low" : "Full");
ESP_LOGI(TAG, "\tbConfigurationValue %d", dev_info.bConfigurationValue); ESP_LOGI(TAG, "\tbConfigurationValue %d", dev_info.bConfigurationValue);
//Todo: Print string descriptors
//Get the device descriptor next //Get the device descriptor next
driver_obj->actions &= ~ACTION_GET_DEV_INFO; driver_obj->actions &= ~ACTION_GET_DEV_INFO;