[vlc-commits] sftp: parse the url only once
Thomas Guillem
git at videolan.org
Thu Dec 7 09:27:57 CET 2017
vlc/vlc-3.0 | branch: master | Thomas Guillem <thomas at gllm.fr> | Wed Dec 6 09:34:34 2017 +0100| [73844599b27906d169b0debe505d733bde9ef58b] | committer: Thomas Guillem
sftp: parse the url only once
And duplicate url.psz_path before decoding it.
(cherry picked from commit 66c293af26343e42576068670229bcefca0a9c33)
Signed-off-by: Thomas Guillem <thomas at gllm.fr>
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=73844599b27906d169b0debe505d733bde9ef58b
---
modules/access/sftp.c | 27 +++++++++++++--------------
1 file changed, 13 insertions(+), 14 deletions(-)
diff --git a/modules/access/sftp.c b/modules/access/sftp.c
index d8f9845bb5..d6724dd71c 100644
--- a/modules/access/sftp.c
+++ b/modules/access/sftp.c
@@ -231,11 +231,9 @@ static int Open( vlc_object_t* p_this )
{
stream_t* p_access = (stream_t*)p_this;
access_sys_t* p_sys;
- vlc_url_t credential_url;
vlc_credential credential;
- const char* psz_path;
+ char* psz_path = NULL;
char *psz_session_username = NULL;
- char* psz_remote_home = NULL;
char* psz_home = NULL;
int i_port;
vlc_url_t url;
@@ -251,12 +249,15 @@ static int Open( vlc_object_t* p_this )
p_sys->i_socket = -1;
- vlc_UrlParse( &credential_url, p_access->psz_url );
- vlc_credential_init( &credential, &credential_url );
-
/* Parse the URL */
vlc_UrlParse( &url, p_access->psz_url );
- vlc_uri_decode( url.psz_path );
+ vlc_credential_init( &credential, &url );
+ if( url.psz_path != NULL )
+ {
+ psz_path = vlc_uri_decode_duplicate( url.psz_path );
+ if( psz_path == NULL )
+ goto error;
+ }
/* Check for some parameters */
if( EMPTY_STR( url.psz_host ) )
@@ -405,12 +406,12 @@ static int Open( vlc_object_t* p_this )
}
/* No path, default to user Home */
- if( !url.psz_path )
+ if( !psz_path )
{
const size_t i_size = 1024;
int i_read;
- psz_remote_home = malloc( i_size );
+ char* psz_remote_home = malloc( i_size );
if( !psz_remote_home )
goto error;
@@ -420,6 +421,7 @@ static int Open( vlc_object_t* p_this )
if( i_read <= 0 )
{
msg_Err( p_access, "Impossible to get the Home directory" );
+ free( psz_remote_home );
goto error;
}
psz_remote_home[i_read] = '\0';
@@ -436,8 +438,6 @@ static int Open( vlc_object_t* p_this )
}
free( base );
}
- else
- psz_path = url.psz_path;
/* Get some information */
LIBSSH2_SFTP_ATTRIBUTES attributes;
@@ -485,11 +485,10 @@ static int Open( vlc_object_t* p_this )
error:
free( psz_home );
- free( psz_remote_home );
free( psz_session_username );
- vlc_UrlClean( &url );
+ free( psz_path );
vlc_credential_clean( &credential );
- vlc_UrlClean( &credential_url );
+ vlc_UrlClean( &url );
if( i_result != VLC_SUCCESS ) {
Close( p_this );
}
More information about the vlc-commits
mailing list