[v5,28/52] net/cnxk: replace strerror with reentrant version

Message ID 20241104111037.3632161-29-huangdengdui@huawei.com (mailing list archive)
State Superseded, archived
Delegated to: Thomas Monjalon
Headers
Series replace strerror |

Checks

Context Check Description
ci/checkpatch success coding style OK

Commit Message

huangdengdui Nov. 4, 2024, 11:10 a.m. UTC
The function strerror() is insecure in a multi-thread environment.
This patch uses strerror_r() to replace it.

Signed-off-by: Dengdui Huang <huangdengdui@huawei.com>
Acked-by: Chengwen Feng <fengchengwen@huawei.com>
Acked-by: Morten Brørup <mb@smartsharesystems.com>
Acked-by: Huisong Li <lihuisong@huawei.com>
---
 drivers/net/cnxk/cnxk_rep_msg.c | 9 +++++++--
 1 file changed, 7 insertions(+), 2 deletions(-)
  

Patch

diff --git a/drivers/net/cnxk/cnxk_rep_msg.c b/drivers/net/cnxk/cnxk_rep_msg.c
index a222e2b5cd..c1c10eab5b 100644
--- a/drivers/net/cnxk/cnxk_rep_msg.c
+++ b/drivers/net/cnxk/cnxk_rep_msg.c
@@ -111,6 +111,7 @@  send_message_on_socket(int socketfd, void *data, uint32_t len, int afd)
 static int
 open_socket_ctrl_channel(void)
 {
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct sockaddr_un un;
 	int sock_fd;
 
@@ -141,13 +142,17 @@  open_socket_ctrl_channel(void)
 	strncpy(un.sun_path, CNXK_ESWITCH_CTRL_MSG_SOCK_PATH, sizeof(un.sun_path) - 1);
 
 	if (bind(sock_fd, (struct sockaddr *)&un, sizeof(un)) < 0) {
-		plt_err("Failed to bind %s: %s", un.sun_path, strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		plt_err("Failed to bind %s: %s", un.sun_path, errmsg);
 		close(sock_fd);
 		return -errno;
 	}
 
 	if (listen(sock_fd, 1) < 0) {
-		plt_err("Failed to listen, err %s", strerror(errno));
+		if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+			snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
+		plt_err("Failed to listen, err %s", errmsg);
 		close(sock_fd);
 		return -errno;
 	}