Changeset 16c7c7141889b674a61da67a83a470323ad6f660

Show
Ignore:
Timestamp:
27/09/05 18:18:11 (3 years ago)
Author:
Benjamin Pracht <bigben@videolan.org>
git-committer:
Benjamin Pracht <bigben@videolan.org> 1127837891 +0000
git-parent:

[6064cdb5e2d13ca044d3f3934f7225d54fa0c70f]

git-author:
Benjamin Pracht <bigben@videolan.org> 1127837891 +0000
Message:

* Fix a double free and the size of a memory allocation
* Only call gnome_vfs_escape_path_string on the path part of the uri, since the functions in gnomevfs that are supposed to make the host/user/path separation are broken (they will escape passwords too)
* Trying to open a file with http on a system with non latin1 encoding may still fail (testing welcomed).
* Don't call gnome_vfs_make_uri_from_input_with_dirs since this will fail on a path with special caracters, but gnome_vfs_expand_initial_tilde and gnome_vfs_make_uri_from_shell_arg

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • modules/access/gnomevfs.c

    r95024e0 r16c7c71  
    3434 
    3535#include "charset.h" 
     36#include "network.h" 
    3637 
    3738/***************************************************************************** 
     
    8889    char           *psz = NULL; 
    8990    char           *psz_uri = NULL; 
     91    char           *psz_unescaped = NULL; 
     92    char           *psz_expand_tilde = NULL; 
    9093    GnomeVFSURI    *p_uri = NULL; 
    9194    GnomeVFSResult  i_ret; 
     
    126129    { 
    127130        psz_name = malloc( strlen( p_access->psz_access ) + 
    128                                             strlen( p_access->psz_path ) + 3 ); 
    129         strcpy( psz_name, p_access->psz_access ); 
    130         strcat( psz_name, "://" ); 
    131         strcat( psz_name, p_access->psz_path ); 
     131                                            strlen( p_access->psz_path ) + 4 ); 
     132        sprintf( psz_name, "%s://%s", p_access->psz_access, 
     133                                                    p_access->psz_path ); 
    132134    } 
    133135    else 
     
    135137        psz_name = strdup( p_access->psz_path ); 
    136138    } 
    137  
    138139    psz = ToLocale( psz_name ); 
    139  
    140     /* Use gnome_vfs_make_uri_from_input_with_dirs for local paths, as it deals 
    141        relative directories, and gnome_vfs_make_uri_from_input_with_dirs 
    142        otherwise */ 
    143     psz_uri = gnome_vfs_make_uri_from_input_with_dirs( psz, 
    144                                     GNOME_VFS_MAKE_URI_DIR_CURRENT); 
    145     if( *psz_uri != '/' ) 
    146     { 
    147         g_free( psz_uri ); 
    148         psz_uri = gnome_vfs_escape_host_and_path_string( psz ); 
    149     } 
    150  
     140    psz_expand_tilde = gnome_vfs_expand_initial_tilde( psz ); 
     141    LocaleFree( psz ); 
     142 
     143    psz_unescaped = gnome_vfs_make_uri_from_shell_arg( psz_expand_tilde ); 
     144 
     145   /* gnome_vfs_make_uri_from_shell_arg will only escape the uri 
     146      for relative paths. So we need to use 
     147      gnome_vfs_escape_host_and_path_string in other cases. */ 
     148 
     149    if( !strcmp( psz_unescaped, psz_expand_tilde ) ) 
     150    { 
     151    /* Now we are sure that we have a complete valid unescaped URI beginning 
     152       with the protocol. We want to escape it. However, gnomevfs's escaping 
     153       function are broken and will try to escape characters un the username/ 
     154       password field. So parse the URI with vlc_UrlParse ans only escape the 
     155       path */ 
     156 
     157        vlc_url_t url; 
     158        char *psz_escaped_path; 
     159        char *psz_path_begin; 
     160 
     161        vlc_UrlParse( &url, psz_unescaped, 0 ); 
     162 
     163        psz_escaped_path = gnome_vfs_escape_path_string( url.psz_path ); 
     164 
     165    /* Now let's reconstruct a valid URI from all that stuff */ 
     166        psz_path_begin = strstr( psz_unescaped, url.psz_path ); 
     167        *psz_path_begin = '\0'; 
     168        psz_uri = malloc( strlen( psz_unescaped ) + 
     169                                        strlen( psz_escaped_path ) + 1 ); 
     170        sprintf( psz_uri, "%s%s",psz_unescaped, psz_escaped_path ); 
     171 
     172        g_free( psz_escaped_path ); 
     173        g_free( psz_unescaped ); 
     174    } 
     175    else 
     176    { 
     177        psz_uri = psz_unescaped; 
     178    } 
     179 
     180    g_free( psz_expand_tilde ); 
    151181    p_uri = gnome_vfs_uri_new( psz_uri ); 
    152182    if( p_uri ) 
     
    158188        if( i_ret ) 
    159189        { 
    160             msg_Err( p_access, "cannot get file info (%s)",  
    161                                     gnome_vfs_result_to_string( i_ret ) ); 
     190            msg_Err( p_access, "cannot get file info for uri %s (%s)",  
     191                                psz_uri, gnome_vfs_result_to_string( i_ret ) ); 
    162192            gnome_vfs_file_info_unref( p_sys->p_file_info ); 
    163193            gnome_vfs_uri_unref( p_uri); 
    164194            free( p_sys ); 
    165             free( psz_uri ); 
     195            g_free( psz_uri ); 
    166196            free( psz_name ); 
    167197            return VLC_EGENERIC; 
     
    171201    { 
    172202        msg_Warn( p_access, "cannot parse MRL %s or unsupported protocol", psz_name ); 
    173         LocaleFree( psz ); 
    174203        g_free( psz_uri ); 
    175204        free( p_sys ); 
     
    177206        return VLC_EGENERIC; 
    178207    } 
    179     LocaleFree( psz ); 
    180208 
    181209    msg_Dbg( p_access, "opening file `%s'", psz_uri ); 
     
    186214                                gnome_vfs_result_to_string( i_ret ) ); 
    187215 
    188         LocaleFree( psz ); 
     216        gnome_vfs_uri_unref( p_uri); 
    189217        g_free( psz_uri ); 
    190         gnome_vfs_uri_unref( p_uri); 
    191218        free( p_sys );  
    192         free( psz_uri ); 
    193219        free( psz_name ); 
    194220        return VLC_EGENERIC; 
     
    223249        msg_Err( p_access, "file %s is empty, aborting", psz_name ); 
    224250        gnome_vfs_file_info_unref( p_sys->p_file_info ); 
     251        gnome_vfs_uri_unref( p_uri); 
    225252        free( p_sys ); 
    226         free( psz_uri ); 
     253        g_free( psz_uri ); 
    227254        free( psz_name ); 
    228255        return VLC_EGENERIC;