From 542d07d34a3d51507f9656bdc31a03adc7b9771e Mon Sep 17 00:00:00 2001 From: "hrushikesh.bhosale" Date: Wed, 7 May 2025 11:50:39 +0530 Subject: [PATCH] feat(http_server): httpd register handler strdup failure case check In httpd_register_uri_handler api, for the strdup function failure case was not checked and not returned any error by freeing previously allocated memory, if the memory allocation for strdup function did not gets successful. Closes https://github.com/espressif/esp-idf/issues/15878 --- components/esp_http_server/src/httpd_uri.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/components/esp_http_server/src/httpd_uri.c b/components/esp_http_server/src/httpd_uri.c index 5746febc74..64befe83e0 100644 --- a/components/esp_http_server/src/httpd_uri.c +++ b/components/esp_http_server/src/httpd_uri.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -171,6 +171,12 @@ esp_err_t httpd_register_uri_handler(httpd_handle_t handle, hd->hd_calls[i]->handle_ws_control_frames = uri_handler->handle_ws_control_frames; if (uri_handler->supported_subprotocol) { hd->hd_calls[i]->supported_subprotocol = strdup(uri_handler->supported_subprotocol); + if (hd->hd_calls[i]->supported_subprotocol == NULL) { + /* Failed to allocate memory */ + free((void *)hd->hd_calls[i]->uri); + free(hd->hd_calls[i]); + return ESP_ERR_HTTPD_ALLOC_MEM; + } } else { hd->hd_calls[i]->supported_subprotocol = NULL; }