Fixed a NULL pointer dereference on sftp initialization failure.
Added some more debug logs.
This commit is contained in:
parent
ee332e0c8e
commit
9cb69f77f1
12
lib/ssh.c
12
lib/ssh.c
@ -352,6 +352,7 @@ CURLcode Curl_ssh_connect(struct connectdata *conn, bool *done)
|
|||||||
*/
|
*/
|
||||||
authlist = libssh2_userauth_list(ssh->ssh_session, ssh->user,
|
authlist = libssh2_userauth_list(ssh->ssh_session, ssh->user,
|
||||||
strlen(ssh->user));
|
strlen(ssh->user));
|
||||||
|
infof(data, "SSH authentication methods available: %s\n", authlist);
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Check the supported auth types in the order I feel is most secure with the
|
* Check the supported auth types in the order I feel is most secure with the
|
||||||
@ -375,20 +376,26 @@ CURLcode Curl_ssh_connect(struct connectdata *conn, bool *done)
|
|||||||
|
|
||||||
curl_free(home);
|
curl_free(home);
|
||||||
|
|
||||||
|
infof(conn->data, "Using ssh public key file %s\n", rsa_pub);
|
||||||
|
infof(conn->data, "Using ssh private key file %s\n", rsa);
|
||||||
|
|
||||||
if (rsa_pub[0]) {
|
if (rsa_pub[0]) {
|
||||||
/* The function below checks if the files exists, no need to stat() here.
|
/* The function below checks if the files exists, no need to stat() here.
|
||||||
*/
|
*/
|
||||||
if (libssh2_userauth_publickey_fromfile(ssh->ssh_session, ssh->user,
|
if (libssh2_userauth_publickey_fromfile(ssh->ssh_session, ssh->user,
|
||||||
rsa_pub, rsa, "") == 0) {
|
rsa_pub, rsa, "") == 0) {
|
||||||
authed = TRUE;
|
authed = TRUE;
|
||||||
|
infof(conn->data, "Initialized SSH public key authentication\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!authed &&
|
if (!authed &&
|
||||||
(data->set.ssh_auth_types & CURLSSH_AUTH_PASSWORD) &&
|
(data->set.ssh_auth_types & CURLSSH_AUTH_PASSWORD) &&
|
||||||
(strstr(authlist, "password") != NULL)) {
|
(strstr(authlist, "password") != NULL)) {
|
||||||
if (!libssh2_userauth_password(ssh->ssh_session, ssh->user, ssh->passwd))
|
if (!libssh2_userauth_password(ssh->ssh_session, ssh->user, ssh->passwd)) {
|
||||||
authed = TRUE;
|
authed = TRUE;
|
||||||
|
infof(conn->data, "Initialized password authentication\n");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!authed && (data->set.ssh_auth_types & CURLSSH_AUTH_HOST) &&
|
if (!authed && (data->set.ssh_auth_types & CURLSSH_AUTH_HOST) &&
|
||||||
(strstr(authlist, "hostbased") != NULL)) {
|
(strstr(authlist, "hostbased") != NULL)) {
|
||||||
@ -400,6 +407,7 @@ CURLcode Curl_ssh_connect(struct connectdata *conn, bool *done)
|
|||||||
strlen(ssh->user),
|
strlen(ssh->user),
|
||||||
&kbd_callback) == 0) {
|
&kbd_callback) == 0) {
|
||||||
authed = TRUE;
|
authed = TRUE;
|
||||||
|
infof(conn->data, "Initialized keyboard interactive authentication\n");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -424,8 +432,6 @@ CURLcode Curl_ssh_connect(struct connectdata *conn, bool *done)
|
|||||||
ssh->sftp_session = libssh2_sftp_init(ssh->ssh_session);
|
ssh->sftp_session = libssh2_sftp_init(ssh->ssh_session);
|
||||||
if (ssh->sftp_session == NULL) {
|
if (ssh->sftp_session == NULL) {
|
||||||
failf(data, "Failure initialising sftp session\n");
|
failf(data, "Failure initialising sftp session\n");
|
||||||
libssh2_sftp_shutdown(ssh->sftp_session);
|
|
||||||
ssh->sftp_session = NULL;
|
|
||||||
libssh2_session_free(ssh->ssh_session);
|
libssh2_session_free(ssh->ssh_session);
|
||||||
ssh->ssh_session = NULL;
|
ssh->ssh_session = NULL;
|
||||||
return CURLE_FAILED_INIT;
|
return CURLE_FAILED_INIT;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user