From e9844bd613e70da1349674897f937bb28de5ec33 Mon Sep 17 00:00:00 2001 From: "hrushikesh.bhosale" Date: Mon, 2 Dec 2024 12:16:40 +0530 Subject: [PATCH] fix(protocomm): Added check for cur_cookie_session_id Added check to check whether the value of cur_cookie_session_id is -1 or not, if yes the return with error log message --- .../protocomm/src/transports/protocomm_httpd.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/components/protocomm/src/transports/protocomm_httpd.c b/components/protocomm/src/transports/protocomm_httpd.c index eaa0019577..8fb953b8de 100644 --- a/components/protocomm/src/transports/protocomm_httpd.c +++ b/components/protocomm/src/transports/protocomm_httpd.c @@ -1,5 +1,5 @@ /* - * SPDX-FileCopyrightText: 2018-2022 Espressif Systems (Shanghai) CO LTD + * SPDX-FileCopyrightText: 2018-2024 Espressif Systems (Shanghai) CO LTD * * SPDX-License-Identifier: Apache-2.0 */ @@ -49,7 +49,11 @@ static esp_err_t common_post_handler(httpd_req_t *req) ssize_t outlen; int cur_sock_session_id = httpd_req_to_sockfd(req); - int cur_cookie_session_id = 0; + if (cur_sock_session_id < 0) { + ESP_LOGE(TAG, "Post failed, incorrect file descriptor %d", cur_sock_session_id); + return ESP_FAIL; + } + uint32_t cur_cookie_session_id = 0; char cookie_buf[20] = {0}; bool same_session = false; @@ -91,11 +95,11 @@ static esp_err_t common_post_handler(httpd_req_t *req) } /* Initialize new security session. A random number will be assigned to the session */ cur_cookie_session_id = esp_random(); - ESP_LOGD(TAG, "Creating new session: %u", cur_cookie_session_id); + ESP_LOGD(TAG, "Creating new session: %" PRIu32, cur_cookie_session_id); if (pc_httpd->sec && pc_httpd->sec->new_transport_session) { ret = pc_httpd->sec->new_transport_session(pc_httpd->sec_inst, cur_cookie_session_id); if (ret != ESP_OK) { - ESP_LOGE(TAG, "Failed to launch new session with ID: %u", cur_cookie_session_id); + ESP_LOGE(TAG, "Failed to launch new session with ID: %" PRIu32, cur_cookie_session_id); ret = ESP_FAIL; goto out; }