1
0
mirror of https://git.libssh.org/projects/libssh.git synced 2025-11-29 01:03:57 +03:00

connect: Check return value of getsockopt().

This commit is contained in:
Andreas Schneider
2013-06-17 12:47:21 +02:00
parent 0ba075e9ce
commit 9ee45a18d7

View File

@@ -139,6 +139,7 @@ static int ssh_connect_ai_timeout(ssh_session session, const char *host,
int timeout_ms; int timeout_ms;
ssh_pollfd_t fds; ssh_pollfd_t fds;
int rc = 0; int rc = 0;
int ret;
socklen_t len = sizeof(rc); socklen_t len = sizeof(rc);
enter_function(); enter_function();
@@ -181,11 +182,11 @@ static int ssh_connect_ai_timeout(ssh_session session, const char *host,
leave_function(); leave_function();
return -1; return -1;
} }
rc = 0; rc = -1;
/* Get connect(2) return code. Zero means no error */ /* Get connect(2) return code. Zero means no error */
getsockopt(s, SOL_SOCKET, SO_ERROR,(char *) &rc, &len); ret = getsockopt(s, SOL_SOCKET, SO_ERROR,(char *) &rc, &len);
if (rc != 0) { if (ret < 0 || rc != 0) {
ssh_set_error(session, SSH_FATAL, ssh_set_error(session, SSH_FATAL,
"Connect to %s:%d failed: %s", host, port, strerror(rc)); "Connect to %s:%d failed: %s", host, port, strerror(rc));
ssh_connect_socket_close(s); ssh_connect_socket_close(s);