From a9591d1c1f9b5e13594625b0aa09a0d45e2a1837 Mon Sep 17 00:00:00 2001 From: Shubham Kulkarni Date: Mon, 30 Mar 2020 11:51:23 +0530 Subject: [PATCH 1/3] esp_http_client.c: In esp_http_client_read, add fix to return (-1) if esp_transport_read fails --- components/esp_http_client/esp_http_client.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/components/esp_http_client/esp_http_client.c b/components/esp_http_client/esp_http_client.c index 8cbc2c06be..f645938197 100644 --- a/components/esp_http_client/esp_http_client.c +++ b/components/esp_http_client/esp_http_client.c @@ -860,7 +860,11 @@ int esp_http_client_read(esp_http_client_handle_t client, char *buffer, int len) } ESP_LOG_LEVEL(sev, TAG, "esp_transport_read returned:%d and errno:%d ", rlen, errno); } - return ridx; + if (rlen < 0 && ridx == 0) { + return ESP_FAIL; + } else { + return ridx; + } } res_buffer->output_ptr = buffer + ridx; http_parser_execute(client->parser, client->parser_settings, res_buffer->data, rlen); From 9fe1380b7ffeed15164b7f876ed8e39338ba165a Mon Sep 17 00:00:00 2001 From: Shubham Kulkarni Date: Mon, 30 Mar 2020 11:52:38 +0530 Subject: [PATCH 2/3] esp_https_ota.c: Add fix to return failure if (-1) is returned from esp_http_client_read Closes https://github.com/espressif/esp-idf/issues/4960 --- components/esp_https_ota/src/esp_https_ota.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/components/esp_https_ota/src/esp_https_ota.c b/components/esp_https_ota/src/esp_https_ota.c index 4bab1dcdbd..98df98bbbb 100644 --- a/components/esp_https_ota/src/esp_https_ota.c +++ b/components/esp_https_ota/src/esp_https_ota.c @@ -78,10 +78,7 @@ static esp_err_t _http_handle_response_code(esp_http_client_handle_t http_client * to clear the response buffer of http_client. */ int data_read = esp_http_client_read(http_client, upgrade_data_buf, DEFAULT_OTA_BUF_SIZE); - if (data_read < 0) { - ESP_LOGE(TAG, "Error: SSL data read error"); - return ESP_FAIL; - } else if (data_read == 0) { + if (data_read <= 0) { return ESP_OK; } } @@ -235,10 +232,10 @@ esp_err_t esp_https_ota_get_img_desc(esp_https_ota_handle_t https_ota_handle, es (handle->ota_upgrade_buf + bytes_read), data_read_size); /* - * As esp_http_client_read never returns negative error code, we rely on + * As esp_http_client_read doesn't return negative error code if select fails, we rely on * `errno` to check for underlying transport connectivity closure if any */ - if (errno == ENOTCONN || errno == ECONNRESET || errno == ECONNABORTED) { + if (errno == ENOTCONN || errno == ECONNRESET || errno == ECONNABORTED || data_read < 0) { ESP_LOGE(TAG, "Connection closed, errno = %d", errno); break; } @@ -294,7 +291,7 @@ esp_err_t esp_https_ota_perform(esp_https_ota_handle_t https_ota_handle) */ bool is_recv_complete = esp_https_ota_is_complete_data_received(https_ota_handle); /* - * As esp_http_client_read never returns negative error code, we rely on + * As esp_http_client_read doesn't return negative error code if select fails, we rely on * `errno` to check for underlying transport connectivity closure if any. * Incase the complete data has not been received but the server has sent * an ENOTCONN or ECONNRESET, failure is returned. We close with success @@ -309,6 +306,8 @@ esp_err_t esp_https_ota_perform(esp_https_ota_handle_t https_ota_handle) ESP_LOGI(TAG, "Connection closed"); } else if (data_read > 0) { return _ota_write(handle, (const void *)handle->ota_upgrade_buf, data_read); + } else { + return ESP_FAIL; } handle->state = ESP_HTTPS_OTA_SUCCESS; break; From 0253a372be1dd85a9554cabcfe43d4a29217d15c Mon Sep 17 00:00:00 2001 From: Shubham Kulkarni Date: Wed, 8 Jul 2020 09:52:53 +0530 Subject: [PATCH 3/3] Increase receive timeout in sdkconfig.ci to fix CI failures --- examples/system/ota/advanced_https_ota/sdkconfig.ci | 2 +- examples/system/ota/native_ota_example/sdkconfig.ci | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/system/ota/advanced_https_ota/sdkconfig.ci b/examples/system/ota/advanced_https_ota/sdkconfig.ci index 577551e000..0edbed76b0 100644 --- a/examples/system/ota/advanced_https_ota/sdkconfig.ci +++ b/examples/system/ota/advanced_https_ota/sdkconfig.ci @@ -1,4 +1,4 @@ CONFIG_EXAMPLE_FIRMWARE_UPGRADE_URL="FROM_STDIN" CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK=y CONFIG_EXAMPLE_SKIP_VERSION_CHECK=y -CONFIG_EXAMPLE_OTA_RECV_TIMEOUT=2000 +CONFIG_EXAMPLE_OTA_RECV_TIMEOUT=3000 diff --git a/examples/system/ota/native_ota_example/sdkconfig.ci b/examples/system/ota/native_ota_example/sdkconfig.ci index fad2c0a8c6..1908291986 100644 --- a/examples/system/ota/native_ota_example/sdkconfig.ci +++ b/examples/system/ota/native_ota_example/sdkconfig.ci @@ -1,4 +1,4 @@ CONFIG_EXAMPLE_FIRMWARE_UPG_URL="FROM_STDIN" CONFIG_EXAMPLE_SKIP_COMMON_NAME_CHECK=y CONFIG_EXAMPLE_SKIP_VERSION_CHECK=y -CONFIG_EXAMPLE_OTA_RECV_TIMEOUT=2000 +CONFIG_EXAMPLE_OTA_RECV_TIMEOUT=3000