mirror of
https://git.libssh.org/projects/libssh.git
synced 2026-02-04 12:20:42 +09:00
Make ssh_socket_set_fd() return errors
and properly check the return value where it is used Signed-off-by: Jakub Jelen <jjelen@redhat.com> Reviewed-by: Andreas Schneider <asn@cryptomilk.org>
This commit is contained in:
@@ -33,7 +33,7 @@ void ssh_socket_cleanup(void);
|
||||
ssh_socket ssh_socket_new(ssh_session session);
|
||||
void ssh_socket_reset(ssh_socket s);
|
||||
void ssh_socket_free(ssh_socket s);
|
||||
void ssh_socket_set_fd(ssh_socket s, socket_t fd);
|
||||
int ssh_socket_set_fd(ssh_socket s, socket_t fd);
|
||||
socket_t ssh_socket_get_fd(ssh_socket s);
|
||||
void ssh_socket_set_connected(ssh_socket s, struct ssh_poll_handle_struct *p);
|
||||
int ssh_socket_unix(ssh_socket s, const char *path);
|
||||
|
||||
@@ -210,8 +210,7 @@ int ssh_set_agent_socket(ssh_session session, socket_t fd)
|
||||
return SSH_ERROR;
|
||||
}
|
||||
|
||||
ssh_socket_set_fd(session->agent->sock, fd);
|
||||
return SSH_OK;
|
||||
return ssh_socket_set_fd(session->agent->sock, fd);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -505,7 +505,10 @@ int ssh_bind_accept_fd(ssh_bind sshbind, ssh_session session, socket_t fd)
|
||||
ssh_set_error_oom(sshbind);
|
||||
return SSH_ERROR;
|
||||
}
|
||||
ssh_socket_set_fd(session->socket, fd);
|
||||
rc = ssh_socket_set_fd(session->socket, fd);
|
||||
if (rc != SSH_OK) {
|
||||
return rc;
|
||||
}
|
||||
handle = ssh_socket_get_poll_handle(session->socket);
|
||||
if (handle == NULL) {
|
||||
ssh_set_error_oom(sshbind);
|
||||
|
||||
@@ -602,8 +602,7 @@ int ssh_connect(ssh_session session)
|
||||
|
||||
if (session->opts.fd != SSH_INVALID_SOCKET) {
|
||||
session->session_state = SSH_SESSION_STATE_SOCKET_CONNECTED;
|
||||
ssh_socket_set_fd(session->socket, session->opts.fd);
|
||||
ret = SSH_OK;
|
||||
ret = ssh_socket_set_fd(session->socket, session->opts.fd);
|
||||
#ifndef _WIN32
|
||||
#ifdef HAVE_PTHREAD
|
||||
} else if (ssh_libssh_proxy_jumps() &&
|
||||
|
||||
37
src/socket.c
37
src/socket.c
@@ -440,7 +440,7 @@ int ssh_socket_unix(ssh_socket s, const char *path)
|
||||
ssh_set_error(s->session, SSH_FATAL,
|
||||
"Error from socket(AF_UNIX, SOCK_STREAM, 0): %s",
|
||||
ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
|
||||
return -1;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
|
||||
#ifndef _WIN32
|
||||
@@ -449,7 +449,7 @@ int ssh_socket_unix(ssh_socket s, const char *path)
|
||||
"Error from fcntl(fd, F_SETFD, 1): %s",
|
||||
ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
|
||||
CLOSE_SOCKET(fd);
|
||||
return -1;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -458,10 +458,9 @@ int ssh_socket_unix(ssh_socket s, const char *path)
|
||||
path,
|
||||
ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
|
||||
CLOSE_SOCKET(fd);
|
||||
return -1;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
ssh_socket_set_fd(s,fd);
|
||||
return 0;
|
||||
return ssh_socket_set_fd(s, fd);
|
||||
}
|
||||
|
||||
/** \internal
|
||||
@@ -519,7 +518,7 @@ void ssh_socket_close(ssh_socket s)
|
||||
* @warning this function updates both the input and output
|
||||
* file descriptors
|
||||
*/
|
||||
void ssh_socket_set_fd(ssh_socket s, socket_t fd)
|
||||
int ssh_socket_set_fd(ssh_socket s, socket_t fd)
|
||||
{
|
||||
ssh_poll_handle h = NULL;
|
||||
|
||||
@@ -531,7 +530,7 @@ void ssh_socket_set_fd(ssh_socket s, socket_t fd)
|
||||
s->state = SSH_SOCKET_CONNECTING;
|
||||
h = ssh_socket_get_poll_handle(s);
|
||||
if (h == NULL) {
|
||||
return;
|
||||
return SSH_ERROR;
|
||||
}
|
||||
|
||||
/* POLLOUT is the event to wait for in a nonblocking connect */
|
||||
@@ -540,6 +539,7 @@ void ssh_socket_set_fd(ssh_socket s, socket_t fd)
|
||||
ssh_poll_add_events(h, POLLWRNORM);
|
||||
#endif
|
||||
}
|
||||
return SSH_OK;
|
||||
}
|
||||
|
||||
/** \internal
|
||||
@@ -889,9 +889,7 @@ int ssh_socket_connect(ssh_socket s,
|
||||
if (fd == SSH_INVALID_SOCKET) {
|
||||
return SSH_ERROR;
|
||||
}
|
||||
ssh_socket_set_fd(s,fd);
|
||||
|
||||
return SSH_OK;
|
||||
return ssh_socket_set_fd(s, fd);
|
||||
}
|
||||
|
||||
#ifdef WITH_EXEC
|
||||
@@ -985,8 +983,16 @@ ssh_socket_connect_proxycommand(ssh_socket s, const char *command)
|
||||
}
|
||||
s->proxy_pid = pid;
|
||||
close(pair[0]);
|
||||
SSH_LOG(SSH_LOG_DEBUG, "ProxyCommand connection pipe: [%d,%d]",pair[0],pair[1]);
|
||||
ssh_socket_set_fd(s, pair[1]);
|
||||
SSH_LOG(SSH_LOG_DEBUG,
|
||||
"ProxyCommand connection pipe: [%d,%d]",
|
||||
pair[0],
|
||||
pair[1]);
|
||||
|
||||
rc = ssh_socket_set_fd(s, pair[1]);
|
||||
if (rc != SSH_OK) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
s->fd_is_socket = 0;
|
||||
h = ssh_socket_get_poll_handle(s);
|
||||
if (h == NULL) {
|
||||
@@ -1276,7 +1282,12 @@ ssh_socket_connect_proxyjump(ssh_socket s)
|
||||
"ProxyJump connection pipe: [%d,%d]",
|
||||
pair[0],
|
||||
pair[1]);
|
||||
ssh_socket_set_fd(s, pair[1]);
|
||||
|
||||
rc = ssh_socket_set_fd(s, pair[1]);
|
||||
if (rc != SSH_OK) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
s->fd_is_socket = 1;
|
||||
h = ssh_socket_get_poll_handle(s);
|
||||
if (h == NULL) {
|
||||
|
||||
Reference in New Issue
Block a user