http: Fix parsing invalid url cause to crash

Reason:
For example, if an url is lack of leading 'http:' by mistake, it causes to http_parser_parse_url() cannot parse http host item,
and then pass the null host pointer to _get_host_header(), crash happens.

Fix:
http added null pointer check now.

Closes https://jira.espressif.com:8443/browse/ESPAT-953
This commit is contained in:
Chen Wu
2021-12-02 14:15:43 +08:00
committed by bot
parent 5548b3b71c
commit 7f1ab6d8d1
2 changed files with 21 additions and 0 deletions

View File

@@ -140,3 +140,16 @@ TEST_CASE("Username and password will not reset if new absolute URL doesnot spec
TEST_ASSERT_NOT_NULL(value);
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);
}