From 5dacf75cefd2213aa5c2ef8a29b39d3ce9f5f91b Mon Sep 17 00:00:00 2001 From: Andrew Borodin Date: Tue, 2 Oct 2018 08:23:14 +0300 Subject: [PATCH] Ticket #3937: fix crash when trying some sftp connections. (sftpfs_recognize_auth_types): fix dereference of NULL returned by libssh2_userauth_list(). Signed-off-by: Andrew Borodin --- src/vfs/sftpfs/connection.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/vfs/sftpfs/connection.c b/src/vfs/sftpfs/connection.c index 537159129..c0e2e2c55 100644 --- a/src/vfs/sftpfs/connection.c +++ b/src/vfs/sftpfs/connection.c @@ -162,8 +162,9 @@ sftpfs_open_socket (struct vfs_s_super *super, GError ** mcerror) * proper enum's values. * * @param super connection data + * @return TRUE if some of authentication methods is available, FALSE otherwise */ -static void +static gboolean sftpfs_recognize_auth_types (struct vfs_s_super *super) { char *userauthlist; @@ -178,6 +179,9 @@ sftpfs_recognize_auth_types (struct vfs_s_super *super) userauthlist = libssh2_userauth_list (super_data->session, super->path_element->user, strlen (super->path_element->user)); + if (userauthlist == NULL) + return FALSE; + if ((strstr (userauthlist, "password") != NULL || strstr (userauthlist, "keyboard-interactive") != NULL) && (super_data->config_auth_type & PASSWORD) != 0) @@ -188,6 +192,8 @@ sftpfs_recognize_auth_types (struct vfs_s_super *super) if ((super_data->config_auth_type & AGENT) != 0) super_data->auth_type |= AGENT; + + return TRUE; } /* --------------------------------------------------------------------------------------------- */ @@ -406,7 +412,14 @@ sftpfs_open_connection (struct vfs_s_super *super, GError ** mcerror) */ super_data->fingerprint = libssh2_hostkey_hash (super_data->session, LIBSSH2_HOSTKEY_HASH_SHA1); - sftpfs_recognize_auth_types (super); + if (!sftpfs_recognize_auth_types (super)) + { + int sftp_errno; + + sftp_errno = libssh2_session_last_errno (super_data->session); + sftpfs_ssherror_to_gliberror (super_data, sftp_errno, mcerror); + return (-1); + } if (!sftpfs_open_connection_ssh_agent (super, mcerror) && !sftpfs_open_connection_ssh_key (super, mcerror)