From f96a118ebf8b9adad46ed7c565dbc294fcff33c4 Mon Sep 17 00:00:00 2001 From: "hrushikesh.bhosale" Date: Fri, 3 Jan 2025 18:31:47 +0530 Subject: [PATCH] feat(https_server): Added checks to verify if uri is empty Added the checks if the URI is empty for the funtions httpd_req_get_url_query_len and httpd_req_get_url_query_str in httpd_parser.c --- components/esp_http_server/include/esp_http_server.h | 3 ++- components/esp_http_server/src/httpd_parse.c | 12 +++++++++++- 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/components/esp_http_server/include/esp_http_server.h b/components/esp_http_server/include/esp_http_server.h index 622d93fb72..a8b22b680b 100644 --- a/components/esp_http_server/include/esp_http_server.h +++ b/components/esp_http_server/include/esp_http_server.h @@ -964,7 +964,7 @@ esp_err_t httpd_req_get_hdr_value_str(httpd_req_t *r, const char *field, char *v * * @return * - 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); @@ -992,6 +992,7 @@ size_t httpd_req_get_url_query_len(httpd_req_t *r); * * @return * - 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_INVALID_ARG : Null arguments * - ESP_ERR_HTTPD_INVALID_REQ : Invalid HTTP request pointer diff --git a/components/esp_http_server/src/httpd_parse.c b/components/esp_http_server/src/httpd_parse.c index 9cd2e26f0a..b520c871b1 100644 --- a/components/esp_http_server/src/httpd_parse.c +++ b/components/esp_http_server/src/httpd_parse.c @@ -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 */ @@ -916,6 +916,11 @@ size_t httpd_req_get_url_query_len(httpd_req_t *r) return 0; } + if (r->uri[0] == '\0') { + ESP_LOGD(TAG, "uri is empty"); + return 0; + } + struct httpd_req_aux *ra = r->aux; struct http_parser_url *res = &ra->url_parse_res; @@ -936,6 +941,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; } + if (r->uri[0] == '\0') { + ESP_LOGD(TAG, "uri is empty"); + return ESP_FAIL; + } + struct httpd_req_aux *ra = r->aux; struct http_parser_url *res = &ra->url_parse_res;