From df1ee8c9e5821f346ccf8b9230f78fd12f21aa84 Mon Sep 17 00:00:00 2001 From: Steve Lhomme <robux4@ycbcr.xyz> Date: Thu, 1 Sep 2022 07:09:49 +0200 Subject: [PATCH] sftp: fix usage of NULL config_GetUserDir result --- modules/access/sftp.c | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/modules/access/sftp.c b/modules/access/sftp.c index 1c05500c0017..36af38f09f55 100644 --- a/modules/access/sftp.c +++ b/modules/access/sftp.c @@ -324,13 +324,17 @@ static int Open( vlc_object_t* p_this ) goto error; psz_home = config_GetUserDir( VLC_HOME_DIR ); - char *psz_knownhosts_file; - if( asprintf( &psz_knownhosts_file, "%s/.ssh/known_hosts", psz_home ) != -1 ) + if (likely(psz_home != NULL)) { - if( libssh2_knownhost_readfile( ssh_knownhosts, psz_knownhosts_file, - LIBSSH2_KNOWNHOST_FILE_OPENSSH ) < 0 ) - msg_Err( p_access, "Failure reading known_hosts '%s'", psz_knownhosts_file ); - free( psz_knownhosts_file ); + char *psz_knownhosts_file; + if( asprintf( &psz_knownhosts_file, "%s/.ssh/known_hosts", psz_home ) != -1 ) + { + if( libssh2_knownhost_readfile( ssh_knownhosts, psz_knownhosts_file, + LIBSSH2_KNOWNHOST_FILE_OPENSSH ) < 0 ) + msg_Err( p_access, "Failure reading known_hosts '%s'", psz_knownhosts_file ); + free( psz_knownhosts_file ); + } + free( psz_home ); } const char *fingerprint = libssh2_session_hostkey( p_sys->ssh_session, &i_len, &i_type ); @@ -558,7 +562,6 @@ static int Open( vlc_object_t* p_this ) i_result = VLC_SUCCESS; error: - free( psz_home ); free( psz_session_username ); free( psz_path ); vlc_credential_clean( &credential ); -- GitLab