Merge branch 'fix/return_esp_err_t_for_httpd_req_get_url_query_str_v5.2' into 'release/v5.2'

feat(https_server): Added checks to verify if uri is empty (v5.2)

See merge request espressif/esp-idf!36288
This commit is contained in:
Mahavir Jain
2025-01-13 11:51:49 +08:00
2 changed files with 13 additions and 2 deletions

View File

@ -957,7 +957,7 @@ esp_err_t httpd_req_get_hdr_value_str(httpd_req_t *r, const char *field, char *v
* *
* @return * @return
* - Length : Query is found in the request URL * - Length : Query is found in the request URL
* - Zero : Query not found / Null arguments / Invalid request * - Zero : Query not found / Null arguments / Invalid request / uri is empty
*/ */
size_t httpd_req_get_url_query_len(httpd_req_t *r); size_t httpd_req_get_url_query_len(httpd_req_t *r);
@ -985,6 +985,7 @@ size_t httpd_req_get_url_query_len(httpd_req_t *r);
* *
* @return * @return
* - ESP_OK : Query is found in the request URL and copied to buffer * - ESP_OK : Query is found in the request URL and copied to buffer
* - ESP_FAIL : uri is empty
* - ESP_ERR_NOT_FOUND : Query not found * - ESP_ERR_NOT_FOUND : Query not found
* - ESP_ERR_INVALID_ARG : Null arguments * - ESP_ERR_INVALID_ARG : Null arguments
* - ESP_ERR_HTTPD_INVALID_REQ : Invalid HTTP request pointer * - ESP_ERR_HTTPD_INVALID_REQ : Invalid HTTP request pointer

View File

@ -1,5 +1,5 @@
/* /*
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD * SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD
* *
* SPDX-License-Identifier: Apache-2.0 * SPDX-License-Identifier: Apache-2.0
*/ */
@ -920,6 +920,11 @@ size_t httpd_req_get_url_query_len(httpd_req_t *r)
return 0; return 0;
} }
if (r->uri[0] == '\0') {
ESP_LOGD(TAG, "uri is empty");
return 0;
}
struct httpd_req_aux *ra = r->aux; struct httpd_req_aux *ra = r->aux;
struct http_parser_url *res = &ra->url_parse_res; struct http_parser_url *res = &ra->url_parse_res;
@ -940,6 +945,11 @@ esp_err_t httpd_req_get_url_query_str(httpd_req_t *r, char *buf, size_t buf_len)
return ESP_ERR_HTTPD_INVALID_REQ; return ESP_ERR_HTTPD_INVALID_REQ;
} }
if (r->uri[0] == '\0') {
ESP_LOGD(TAG, "uri is empty");
return ESP_FAIL;
}
struct httpd_req_aux *ra = r->aux; struct httpd_req_aux *ra = r->aux;
struct http_parser_url *res = &ra->url_parse_res; struct http_parser_url *res = &ra->url_parse_res;