From 4e9367bc414e09da96f6afa228a4eb2ac8f52081 Mon Sep 17 00:00:00 2001 From: Ashish Sharma Date: Tue, 24 Feb 2026 16:29:53 +0800 Subject: [PATCH] fix(esp_http_server): fix ws server subprotocol match --- components/esp_http_server/src/httpd_parse.c | 2 ++ components/esp_http_server/src/httpd_ws.c | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/components/esp_http_server/src/httpd_parse.c b/components/esp_http_server/src/httpd_parse.c index 176a21d8854..b1afd0ad986 100644 --- a/components/esp_http_server/src/httpd_parse.c +++ b/components/esp_http_server/src/httpd_parse.c @@ -509,6 +509,8 @@ static int read_block(httpd_req_t *req, http_parser *parser, size_t offset, size if (new_scratch == NULL) { free(raux->scratch); raux->scratch = NULL; + /* Set last.at to NULL to avoid accidental dereference of dangling pointer */ + parser_data->last.at = NULL; ESP_LOGE(TAG, "Unable to allocate the scratch buffer"); return 0; } diff --git a/components/esp_http_server/src/httpd_ws.c b/components/esp_http_server/src/httpd_ws.c index 949addc674a..b17d2e6eef0 100644 --- a/components/esp_http_server/src/httpd_ws.c +++ b/components/esp_http_server/src/httpd_ws.c @@ -83,7 +83,7 @@ static bool httpd_ws_get_response_subprotocol(const char *supported_subprotocol, char *rest = NULL; char *s = strtok_r(subprotocol, ", ", &rest); do { - if (strncmp(s, supported_subprotocol, sizeof(subprotocol)) == 0) { + if (strncmp(s, supported_subprotocol, strlen(supported_subprotocol)) == 0) { ESP_LOGD(TAG, "Requested subprotocol supported: %s", s); return true; }