Skip to content

Commit c8bb532

Browse files
committed
Merge branch 'fix/return_esp_err_t_for_httpd_req_get_url_query_str_v5.4' into 'release/v5.4'
feat(https_server): Added checks to verify if uri is empty (v5.4) See merge request espressif/esp-idf!36286
2 parents cf1692c + f96a118 commit c8bb532

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

components/esp_http_server/include/esp_http_server.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ esp_err_t httpd_req_get_hdr_value_str(httpd_req_t *r, const char *field, char *v
964964
*
965965
* @return
966966
* - Length : Query is found in the request URL
967-
* - Zero : Query not found / Null arguments / Invalid request
967+
* - Zero : Query not found / Null arguments / Invalid request / uri is empty
968968
*/
969969
size_t httpd_req_get_url_query_len(httpd_req_t *r);
970970

@@ -992,6 +992,7 @@ size_t httpd_req_get_url_query_len(httpd_req_t *r);
992992
*
993993
* @return
994994
* - ESP_OK : Query is found in the request URL and copied to buffer
995+
* - ESP_FAIL : uri is empty
995996
* - ESP_ERR_NOT_FOUND : Query not found
996997
* - ESP_ERR_INVALID_ARG : Null arguments
997998
* - ESP_ERR_HTTPD_INVALID_REQ : Invalid HTTP request pointer

components/esp_http_server/src/httpd_parse.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -916,6 +916,11 @@ size_t httpd_req_get_url_query_len(httpd_req_t *r)
916916
return 0;
917917
}
918918

919+
if (r->uri[0] == '\0') {
920+
ESP_LOGD(TAG, "uri is empty");
921+
return 0;
922+
}
923+
919924
struct httpd_req_aux *ra = r->aux;
920925
struct http_parser_url *res = &ra->url_parse_res;
921926

@@ -936,6 +941,11 @@ esp_err_t httpd_req_get_url_query_str(httpd_req_t *r, char *buf, size_t buf_len)
936941
return ESP_ERR_HTTPD_INVALID_REQ;
937942
}
938943

944+
if (r->uri[0] == '\0') {
945+
ESP_LOGD(TAG, "uri is empty");
946+
return ESP_FAIL;
947+
}
948+
939949
struct httpd_req_aux *ra = r->aux;
940950
struct http_parser_url *res = &ra->url_parse_res;
941951

0 commit comments

Comments
 (0)