Merge branch 'fix/esp_tls_fix_arg_check' into 'master'

fix(esp_tls): Fixed input argument check for public APIs

Closes IDF-8542

See merge request espressif/esp-idf!28358
This commit is contained in:
Aditya Patwardhan 2024-01-29 18:21:42 +08:00
commit d8cc9d39a2

View File

@ -1,5 +1,5 @@
/*
* SPDX-FileCopyrightText: 2019-2023 Espressif Systems (Shanghai) CO LTD
* SPDX-FileCopyrightText: 2019-2024 Espressif Systems (Shanghai) CO LTD
*
* SPDX-License-Identifier: Apache-2.0
*/
@ -131,14 +131,18 @@ static ssize_t tcp_write(esp_tls_t *tls, const char *data, size_t datalen)
ssize_t esp_tls_conn_read(esp_tls_t *tls, void *data, size_t datalen)
{
if (!tls || !data) {
return -1;
}
return tls->read(tls, (char *)data, datalen);
}
ssize_t esp_tls_conn_write(esp_tls_t *tls, const void *data, size_t datalen)
{
if (!tls || !data) {
return -1;
}
return tls->write(tls, (char *)data, datalen);
}
/**
@ -154,6 +158,7 @@ int esp_tls_conn_destroy(esp_tls_t *tls)
}
esp_tls_internal_event_tracker_destroy(tls->error_handle);
free(tls);
tls = NULL;
return ret;
}
return -1; // invalid argument
@ -436,10 +441,7 @@ err:
static int esp_tls_low_level_conn(const char *hostname, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_t *tls)
{
if (!tls) {
ESP_LOGE(TAG, "empty esp_tls parameter");
return -1;
}
esp_err_t esp_ret;
/* These states are used to keep a tab on connection progress in case of non-blocking connect,
and in case of blocking connect these cases will get executed one after the other */
@ -532,6 +534,9 @@ esp_err_t esp_tls_plain_tcp_connect(const char *host, int hostlen, int port, con
int esp_tls_conn_new_sync(const char *hostname, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_t *tls)
{
if (!cfg || !tls || !hostname || hostlen < 0) {
return -1;
}
struct timeval time = {};
gettimeofday(&time, NULL);
uint32_t start_time_ms = (time.tv_sec * 1000) + (time.tv_usec / 1000);
@ -561,6 +566,9 @@ int esp_tls_conn_new_sync(const char *hostname, int hostlen, int port, const esp
*/
int esp_tls_conn_new_async(const char *hostname, int hostlen, int port, const esp_tls_cfg_t *cfg, esp_tls_t *tls)
{
if (!cfg || !tls || !hostname || hostlen < 0) {
return -1;
}
return esp_tls_low_level_conn(hostname, hostlen, port, cfg, tls);
}
@ -580,6 +588,10 @@ static int get_port(const char *url, struct http_parser_url *u)
esp_tls_t *esp_tls_conn_http_new(const char *url, const esp_tls_cfg_t *cfg)
{
if (!url || !cfg) {
return NULL;
}
/* Parse URI */
struct http_parser_url u;
http_parser_url_init(&u);
@ -602,6 +614,10 @@ esp_tls_t *esp_tls_conn_http_new(const char *url, const esp_tls_cfg_t *cfg)
*/
int esp_tls_conn_http_new_sync(const char *url, const esp_tls_cfg_t *cfg, esp_tls_t *tls)
{
if (!url || !cfg || !tls) {
return -1;
}
/* Parse URI */
struct http_parser_url u;
http_parser_url_init(&u);