kopia lustrzana https://github.com/espressif/esp-idf
Merge branch 'bugfix/invalid_url_cause_to_crash' into 'master'
http: Fix parsing invalid url cause to crash Closes ESPAT-953 See merge request espressif/esp-idf!16153pull/7905/head^2
commit
fbeb711e06
|
@ -658,6 +658,10 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
|
||||||
const char *user_agent = config->user_agent == NULL ? DEFAULT_HTTP_USER_AGENT : config->user_agent;
|
const char *user_agent = config->user_agent == NULL ? DEFAULT_HTTP_USER_AGENT : config->user_agent;
|
||||||
|
|
||||||
if (config->host != NULL && config->path != NULL) {
|
if (config->host != NULL && config->path != NULL) {
|
||||||
|
if (client->connection_info.host == NULL) {
|
||||||
|
ESP_LOGE(TAG, "invalid host");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
host_name = _get_host_header(client->connection_info.host, client->connection_info.port);
|
host_name = _get_host_header(client->connection_info.host, client->connection_info.port);
|
||||||
if (host_name == NULL) {
|
if (host_name == NULL) {
|
||||||
ESP_LOGE(TAG, "Failed to allocate memory for host header");
|
ESP_LOGE(TAG, "Failed to allocate memory for host header");
|
||||||
|
@ -677,6 +681,10 @@ esp_http_client_handle_t esp_http_client_init(const esp_http_client_config_t *co
|
||||||
ESP_LOGE(TAG, "Failed to set URL");
|
ESP_LOGE(TAG, "Failed to set URL");
|
||||||
goto error;
|
goto error;
|
||||||
}
|
}
|
||||||
|
if (client->connection_info.host == NULL) {
|
||||||
|
ESP_LOGE(TAG, "invalid host");
|
||||||
|
goto error;
|
||||||
|
}
|
||||||
host_name = _get_host_header(client->connection_info.host, client->connection_info.port);
|
host_name = _get_host_header(client->connection_info.host, client->connection_info.port);
|
||||||
if (host_name == NULL) {
|
if (host_name == NULL) {
|
||||||
ESP_LOGE(TAG, "Failed to allocate memory for host header");
|
ESP_LOGE(TAG, "Failed to allocate memory for host header");
|
||||||
|
|
|
@ -132,3 +132,16 @@ TEST_CASE("Username and password will not reset if new absolute URL doesnot spec
|
||||||
TEST_ASSERT_NOT_NULL(value);
|
TEST_ASSERT_NOT_NULL(value);
|
||||||
esp_http_client_cleanup(client);
|
esp_http_client_cleanup(client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Test case to verify that, esp_http_client_init() should return NULL if configuration has url with empty hostname.
|
||||||
|
**/
|
||||||
|
TEST_CASE("esp_http_client_init() should return NULL if configured with wrong url", "[ESP HTTP CLIENT]")
|
||||||
|
{
|
||||||
|
esp_http_client_config_t config = {
|
||||||
|
.url = "//httpbin.org/post",
|
||||||
|
};
|
||||||
|
esp_http_client_handle_t client = esp_http_client_init(&config);
|
||||||
|
TEST_ASSERT_NULL(client);
|
||||||
|
esp_http_client_cleanup(client);
|
||||||
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue