esp_https_ota.c: Add fix to return failure if (-1) is returned from esp_http_client_read
Closes
@@ -79,10 +79,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;
}
}
@@ -236,10 +233,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;
}
@@ -295,7 +292,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
@@ -310,6 +307,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;
