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(-)
@@ -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;
}