From b09db144d8f774b03eb9a28a57754132adc64535 Mon Sep 17 00:00:00 2001 From: Chanwoo Choi Date: Mon, 21 Mar 2022 13:16:50 +0900 Subject: [PATCH] monitor: request-handler: Replace with strerror_r to fix vulnerability issue Change-Id: I399fe56e8305df1ed3aef2b7e55677ea2b463313 Signed-off-by: Chanwoo Choi --- src/monitor/request-handler.c | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/src/monitor/request-handler.c b/src/monitor/request-handler.c index edaabdb..b70f504 100644 --- a/src/monitor/request-handler.c +++ b/src/monitor/request-handler.c @@ -453,6 +453,7 @@ static void handle_request(struct request_client *client, char *buffer) int request_type; int ret; int buffer_len = REQUEST_BUFFER_MAX; + char err_buf[BUFF_MAX]; request_type = split_request_type_and_args(buffer, &args); @@ -644,8 +645,10 @@ static void handle_request(struct request_client *client, char *buffer) } ADD_RESPONSE(response, buffer_len, "%d", ret); - if (send(client->socket_fd, _response, strlen(_response), 0) < 0) - _E("Failed to send respones, error: %s", strerror(errno)); + if (send(client->socket_fd, _response, strlen(_response), 0) < 0) { + strerror_r(errno, err_buf, BUFF_MAX); + _E("Failed to send respones, errno: %d, error: %s", errno, err_buf); + } } static GList *g_request_client_head; @@ -684,6 +687,7 @@ static int request_handler_func(void *data, void **result) char buffer[REQUEST_BUFFER_MAX + 1]; struct request_client *client = (struct request_client *)data; int len; + char err_buf[BUFF_MAX]; _D("Start worker thread for client-%d", client->socket_fd); @@ -695,7 +699,9 @@ static int request_handler_func(void *data, void **result) } if (len < 0) { - _E("Error occurs while receiving request: %s", strerror(errno)); + strerror_r(errno, err_buf, BUFF_MAX); + _E("Error occurs while receiving request: errno: %d, error: %s", + errno, err_buf); goto out; } -- 2.7.4