Skip to content

Commit b3ea50d

Browse files
committed
session client UPDATE check hostname set return value
Refs #460
1 parent 535467d commit b3ea50d

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

src/session_client_ssh.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1517,7 +1517,13 @@ _nc_connect_libssh(ssh_session ssh_session, struct ly_ctx *ctx, struct nc_keepal
15171517
/* remember host */
15181518
host = strdup("localhost");
15191519
NC_CHECK_ERRMEM_GOTO(!host, , fail);
1520-
ssh_options_set(session->ti.libssh.session, SSH_OPTIONS_HOST, host);
1520+
1521+
if (ssh_options_set(session->ti.libssh.session, SSH_OPTIONS_HOST, host) != SSH_OK) {
1522+
ERR(NULL, "Failed to use hostname \"%s\".", host);
1523+
free(host);
1524+
goto fail;
1525+
}
1526+
free(host);
15211527

15221528
/* create and connect socket */
15231529
sock = nc_sock_connect(host, port, -1, ka, NULL, &ip_host);
@@ -1527,8 +1533,6 @@ _nc_connect_libssh(ssh_session ssh_session, struct ly_ctx *ctx, struct nc_keepal
15271533
}
15281534
ssh_options_set(session->ti.libssh.session, SSH_OPTIONS_FD, &sock);
15291535
ssh_set_blocking(session->ti.libssh.session, 0);
1530-
1531-
free(host);
15321536
host = ip_host;
15331537
}
15341538

@@ -1663,7 +1667,10 @@ nc_connect_ssh(const char *host, uint16_t port, struct ly_ctx *ctx)
16631667
}
16641668

16651669
/* set some basic SSH session options */
1666-
ssh_options_set(session->ti.libssh.session, SSH_OPTIONS_HOST, host);
1670+
if (ssh_options_set(session->ti.libssh.session, SSH_OPTIONS_HOST, host) != SSH_OK) {
1671+
ERR(session, "Failed to use hostname \"%s\".", host);
1672+
goto fail;
1673+
}
16671674
ssh_options_set(session->ti.libssh.session, SSH_OPTIONS_PORT, &port_uint);
16681675
ssh_options_set(session->ti.libssh.session, SSH_OPTIONS_USER, username);
16691676
ssh_options_set(session->ti.libssh.session, SSH_OPTIONS_TIMEOUT, &timeout);
@@ -1810,10 +1817,15 @@ nc_accept_callhome_ssh_sock(int sock, const char *host, uint16_t port, struct ly
18101817

18111818
ssh_options_set(sess, SSH_OPTIONS_FD, &sock);
18121819
ssh_set_blocking(sess, 0);
1813-
ssh_options_set(sess, SSH_OPTIONS_HOST, host);
1820+
if (ssh_options_set(sess, SSH_OPTIONS_HOST, host) != SSH_OK) {
1821+
ERR(NULL, "Failed to use hostname \"%s\".", host);
1822+
ssh_free(sess);
1823+
return NULL;
1824+
}
18141825
uint_port = port;
18151826
ssh_options_set(sess, SSH_OPTIONS_PORT, &uint_port);
18161827
ssh_options_set(sess, SSH_OPTIONS_TIMEOUT, &ssh_timeout);
1828+
18171829
if (!ssh_ch_opts.username) {
18181830
pw = nc_getpw(getuid(), NULL, &pw_buf, &buf, &buf_len);
18191831
if (!pw) {
@@ -1826,6 +1838,7 @@ nc_accept_callhome_ssh_sock(int sock, const char *host, uint16_t port, struct ly
18261838
} else {
18271839
ssh_options_set(sess, SSH_OPTIONS_USER, ssh_ch_opts.username);
18281840
}
1841+
18291842
ssh_options_set(sess, SSH_OPTIONS_HOSTKEYS, "ssh-ed25519,ecdsa-sha2-nistp256,"
18301843
"ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-rsa,rsa-sha2-512,rsa-sha2-256,ssh-dss");
18311844
#ifdef HAVE_LIBSSH_OPTIONS_PUBLICKEY_ACCEPTED_TYPES

0 commit comments

Comments
 (0)