Commit 73844599 authored by Thomas Guillem's avatar Thomas Guillem

sftp: parse the url only once

And duplicate url.psz_path before decoding it.

(cherry picked from commit 66c293af)
Signed-off-by: Thomas Guillem's avatarThomas Guillem <thomas@gllm.fr>
parent 04a9ebf0
...@@ -231,11 +231,9 @@ static int Open( vlc_object_t* p_this ) ...@@ -231,11 +231,9 @@ static int Open( vlc_object_t* p_this )
{ {
stream_t* p_access = (stream_t*)p_this; stream_t* p_access = (stream_t*)p_this;
access_sys_t* p_sys; access_sys_t* p_sys;
vlc_url_t credential_url;
vlc_credential credential; vlc_credential credential;
const char* psz_path; char* psz_path = NULL;
char *psz_session_username = NULL; char *psz_session_username = NULL;
char* psz_remote_home = NULL;
char* psz_home = NULL; char* psz_home = NULL;
int i_port; int i_port;
vlc_url_t url; vlc_url_t url;
...@@ -251,12 +249,15 @@ static int Open( vlc_object_t* p_this ) ...@@ -251,12 +249,15 @@ static int Open( vlc_object_t* p_this )
p_sys->i_socket = -1; p_sys->i_socket = -1;
vlc_UrlParse( &credential_url, p_access->psz_url );
vlc_credential_init( &credential, &credential_url );
/* Parse the URL */ /* Parse the URL */
vlc_UrlParse( &url, p_access->psz_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 */ /* Check for some parameters */
if( EMPTY_STR( url.psz_host ) ) if( EMPTY_STR( url.psz_host ) )
...@@ -405,12 +406,12 @@ static int Open( vlc_object_t* p_this ) ...@@ -405,12 +406,12 @@ static int Open( vlc_object_t* p_this )
} }
/* No path, default to user Home */ /* No path, default to user Home */
if( !url.psz_path ) if( !psz_path )
{ {
const size_t i_size = 1024; const size_t i_size = 1024;
int i_read; int i_read;
psz_remote_home = malloc( i_size ); char* psz_remote_home = malloc( i_size );
if( !psz_remote_home ) if( !psz_remote_home )
goto error; goto error;
...@@ -420,6 +421,7 @@ static int Open( vlc_object_t* p_this ) ...@@ -420,6 +421,7 @@ static int Open( vlc_object_t* p_this )
if( i_read <= 0 ) if( i_read <= 0 )
{ {
msg_Err( p_access, "Impossible to get the Home directory" ); msg_Err( p_access, "Impossible to get the Home directory" );
free( psz_remote_home );
goto error; goto error;
} }
psz_remote_home[i_read] = '\0'; psz_remote_home[i_read] = '\0';
...@@ -436,8 +438,6 @@ static int Open( vlc_object_t* p_this ) ...@@ -436,8 +438,6 @@ static int Open( vlc_object_t* p_this )
} }
free( base ); free( base );
} }
else
psz_path = url.psz_path;
/* Get some information */ /* Get some information */
LIBSSH2_SFTP_ATTRIBUTES attributes; LIBSSH2_SFTP_ATTRIBUTES attributes;
...@@ -485,11 +485,10 @@ static int Open( vlc_object_t* p_this ) ...@@ -485,11 +485,10 @@ static int Open( vlc_object_t* p_this )
error: error:
free( psz_home ); free( psz_home );
free( psz_remote_home );
free( psz_session_username ); free( psz_session_username );
vlc_UrlClean( &url ); free( psz_path );
vlc_credential_clean( &credential ); vlc_credential_clean( &credential );
vlc_UrlClean( &credential_url ); vlc_UrlClean( &url );
if( i_result != VLC_SUCCESS ) { if( i_result != VLC_SUCCESS ) {
Close( p_this ); Close( p_this );
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment