mirror of
https://github.com/espressif/esp-idf.git
synced 2025-07-30 10:47:19 +02:00
esp_https_ota: Fix esp_https_ota_begin may return ESP_OK when http status code is not 200 and may exist memory leak
Closes https://github.com/espressif/esp-idf/issues/8195
This commit is contained in:
@ -1,16 +1,8 @@
|
|||||||
// Copyright 2017-2018 Espressif Systems (Shanghai) PTE LTD
|
/*
|
||||||
//
|
* SPDX-FileCopyrightText: 2017-2022 Espressif Systems (Shanghai) CO LTD
|
||||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
*
|
||||||
// you may not use this file except in compliance with the License.
|
* SPDX-License-Identifier: Apache-2.0
|
||||||
// You may obtain a copy of the License at
|
*/
|
||||||
|
|
||||||
// http://www.apache.org/licenses/LICENSE-2.0
|
|
||||||
//
|
|
||||||
// Unless required by applicable law or agreed to in writing, software
|
|
||||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
||||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
||||||
// See the License for the specific language governing permissions and
|
|
||||||
// limitations under the License.
|
|
||||||
|
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
@ -214,10 +206,18 @@ esp_err_t esp_https_ota_begin(esp_https_ota_config_t *ota_config, esp_https_ota_
|
|||||||
if (https_ota_handle->partial_http_download) {
|
if (https_ota_handle->partial_http_download) {
|
||||||
esp_http_client_set_method(https_ota_handle->http_client, HTTP_METHOD_HEAD);
|
esp_http_client_set_method(https_ota_handle->http_client, HTTP_METHOD_HEAD);
|
||||||
err = esp_http_client_perform(https_ota_handle->http_client);
|
err = esp_http_client_perform(https_ota_handle->http_client);
|
||||||
if (err != ESP_OK || esp_http_client_get_status_code(https_ota_handle->http_client) != HttpStatus_Ok) {
|
if (err == ESP_OK) {
|
||||||
ESP_LOGE(TAG, "Failed to get image length");
|
int status = esp_http_client_get_status_code(https_ota_handle->http_client);
|
||||||
|
if (status != HttpStatus_Ok) {
|
||||||
|
ESP_LOGE(TAG, "Received incorrect http status %d", status);
|
||||||
|
err = ESP_FAIL;
|
||||||
|
goto http_cleanup;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ESP_LOGE(TAG, "ESP HTTP client perform failed: %d", err);
|
||||||
goto http_cleanup;
|
goto http_cleanup;
|
||||||
}
|
}
|
||||||
|
|
||||||
https_ota_handle->image_length = esp_http_client_get_content_length(https_ota_handle->http_client);
|
https_ota_handle->image_length = esp_http_client_get_content_length(https_ota_handle->http_client);
|
||||||
esp_http_client_close(https_ota_handle->http_client);
|
esp_http_client_close(https_ota_handle->http_client);
|
||||||
|
|
||||||
@ -239,7 +239,7 @@ esp_err_t esp_https_ota_begin(esp_https_ota_config_t *ota_config, esp_https_ota_
|
|||||||
err = ota_config->http_client_init_cb(https_ota_handle->http_client);
|
err = ota_config->http_client_init_cb(https_ota_handle->http_client);
|
||||||
if (err != ESP_OK) {
|
if (err != ESP_OK) {
|
||||||
ESP_LOGE(TAG, "http_client_init_cb returned 0x%x", err);
|
ESP_LOGE(TAG, "http_client_init_cb returned 0x%x", err);
|
||||||
goto failure;
|
goto http_cleanup;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -523,7 +523,6 @@ components/esp_hid/src/esp_hidh.c
|
|||||||
components/esp_hid/test/hid_descriptor.h
|
components/esp_hid/test/hid_descriptor.h
|
||||||
components/esp_hid/test/test_esp_hid.c
|
components/esp_hid/test/test_esp_hid.c
|
||||||
components/esp_https_ota/include/esp_https_ota.h
|
components/esp_https_ota/include/esp_https_ota.h
|
||||||
components/esp_https_ota/src/esp_https_ota.c
|
|
||||||
components/esp_hw_support/include/esp_clk.h
|
components/esp_hw_support/include/esp_clk.h
|
||||||
components/esp_hw_support/include/soc/esp_himem.h
|
components/esp_hw_support/include/soc/esp_himem.h
|
||||||
components/esp_hw_support/include/soc/esp_spiram.h
|
components/esp_hw_support/include/soc/esp_spiram.h
|
||||||
|
Reference in New Issue
Block a user