Skip to content

Commit 54e071a

Browse files
committed
Merge branch 'feat/httpd_register_uri_handler_strdup_failure_case_check' into 'master'
Handling httdp_register_uri_handler() strdup function failure case check Closes IDFGH-15208 See merge request espressif/esp-idf!38933
2 parents e178a09 + 542d07d commit 54e071a

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

components/esp_http_server/src/httpd_uri.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* SPDX-FileCopyrightText: 2018-2021 Espressif Systems (Shanghai) CO LTD
2+
* SPDX-FileCopyrightText: 2018-2025 Espressif Systems (Shanghai) CO LTD
33
*
44
* SPDX-License-Identifier: Apache-2.0
55
*/
@@ -171,6 +171,12 @@ esp_err_t httpd_register_uri_handler(httpd_handle_t handle,
171171
hd->hd_calls[i]->handle_ws_control_frames = uri_handler->handle_ws_control_frames;
172172
if (uri_handler->supported_subprotocol) {
173173
hd->hd_calls[i]->supported_subprotocol = strdup(uri_handler->supported_subprotocol);
174+
if (hd->hd_calls[i]->supported_subprotocol == NULL) {
175+
/* Failed to allocate memory */
176+
free((void *)hd->hd_calls[i]->uri);
177+
free(hd->hd_calls[i]);
178+
return ESP_ERR_HTTPD_ALLOC_MEM;
179+
}
174180
} else {
175181
hd->hd_calls[i]->supported_subprotocol = NULL;
176182
}

0 commit comments

Comments
 (0)