[v5,19/52] common/mlx5: replace strerror with reentrant version

Message ID 20241104111037.3632161-20-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/common/mlx5/linux/mlx5_nl.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
  

Patch

diff --git a/drivers/common/mlx5/linux/mlx5_nl.c b/drivers/common/mlx5/linux/mlx5_nl.c
index a5ac4dc543..67fc6c08d9 100644
--- a/drivers/common/mlx5/linux/mlx5_nl.c
+++ b/drivers/common/mlx5/linux/mlx5_nl.c
@@ -1924,18 +1924,21 @@  mlx5_nl_read_events(int nlsk_fd, mlx5_nl_event_cb *cb, void *cb_arg)
 		.msg_iov = &iov,
 		.msg_iovlen = 1,
 	};
+	char errmsg[RTE_STRERR_BUFSIZE];
 	struct nlmsghdr *hdr;
 	ssize_t size;
 
 	while (1) {
 		size = recvmsg(nlsk_fd, &msg, MSG_DONTWAIT);
 		if (size < 0) {
+			if (strerror_r(errno, errmsg, sizeof(errmsg)) != 0)
+				snprintf(errmsg, sizeof(errmsg), "Unknown error %d", errno);
 			if (errno == EAGAIN)
 				return 0;
 			if (errno == EINTR)
 				continue;
 			DRV_LOG(DEBUG, "Failed to receive netlink message: %s",
-				strerror(errno));
+				errmsg);
 			rte_errno = errno;
 			return -rte_errno;
 		}