From d92e389a802763635236c0dc8a52a9fbd9b07703 Mon Sep 17 00:00:00 2001 From: Norbert Pocs Date: Mon, 4 Jul 2022 10:07:44 +0200 Subject: [PATCH] Rewrite strerror to ssh_strerror Signed-off-by: Norbert Pocs Reviewed-by: Jakub Jelen --- src/bind.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/bind.c b/src/bind.c index 5a71244d..7efac473 100644 --- a/src/bind.c +++ b/src/bind.c @@ -79,6 +79,7 @@ static socket_t bind_socket(ssh_bind sshbind, const char *hostname, int opt = 1; socket_t s; int rc; + char err_msg[SSH_ERRNO_MSG_MAX] = {0}; ZERO_STRUCT(hints); @@ -98,7 +99,8 @@ static socket_t bind_socket(ssh_bind sshbind, const char *hostname, ai->ai_socktype, ai->ai_protocol); if (s == SSH_INVALID_SOCKET) { - ssh_set_error(sshbind, SSH_FATAL, "%s", strerror(errno)); + ssh_set_error(sshbind, SSH_FATAL, "%s", + ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX)); freeaddrinfo (ai); return -1; } @@ -108,7 +110,7 @@ static socket_t bind_socket(ssh_bind sshbind, const char *hostname, ssh_set_error(sshbind, SSH_FATAL, "Setting socket options failed: %s", - strerror(errno)); + ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX)); freeaddrinfo (ai); CLOSE_SOCKET(s); return -1; @@ -120,7 +122,7 @@ static socket_t bind_socket(ssh_bind sshbind, const char *hostname, "Binding to %s:%d: %s", hostname, port, - strerror(errno)); + ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX)); freeaddrinfo (ai); CLOSE_SOCKET(s); return -1; @@ -280,9 +282,10 @@ int ssh_bind_listen(ssh_bind sshbind) { } if (listen(fd, 10) < 0) { + char err_msg[] = {0}; ssh_set_error(sshbind, SSH_FATAL, "Listening to socket %d: %s", - fd, strerror(errno)); + fd, ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX)); CLOSE_SOCKET(fd); ssh_key_free(sshbind->dsa); sshbind->dsa = NULL; @@ -586,14 +589,15 @@ int ssh_bind_accept(ssh_bind sshbind, ssh_session session) fd = accept(sshbind->bindfd, NULL, NULL); if (fd == SSH_INVALID_SOCKET) { + char err_msg[SSH_ERRNO_MSG_MAX] = {0}; if (errno == EINTR) { ssh_set_error(sshbind, SSH_EINTR, "Accepting a new connection (child signal error): %s", - strerror(errno)); + ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX)); } else { ssh_set_error(sshbind, SSH_FATAL, "Accepting a new connection: %s", - strerror(errno)); + ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX)); } return SSH_ERROR; }