From e84ad136b94805df8b7414c6dbdcc084f1e4efa9 Mon Sep 17 00:00:00 2001 From: Shubham Kulkarni Date: Mon, 30 Mar 2020 11:52:38 +0530 Subject: [PATCH] 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;