Ignore:
Timestamp:
Oct 2, 2008, 4:24:44 PM (13 years ago)
Author:
charles
Message:

(rpc) fix minor path resolution glitch when serving up clutch files

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/rpc-server.c

    r6825 r6833  
    299299               struct tr_rpc_server *  server )
    300300{
    301     const char *      uri;
    302     struct evbuffer * buf = evbuffer_new( );
     301    char * pch;
     302    char * subpath;
     303    char * filename;
     304    const char * clutchDir = tr_getClutchDir( server->session );
    303305
    304306    assert( !strncmp( req->uri, "/transmission/web/", 18 ) );
    305307
    306     evbuffer_add_printf( buf, "%s%s", tr_getClutchDir(
    307                              server->session ), TR_PATH_DELIMITER_STR );
    308     uri = req->uri + 18;
    309     if( ( *uri == '?' ) || ( *uri == '\0' ) )
    310         evbuffer_add_printf( buf, "index.html" );
    311     else
    312     {
    313         const char * pch = strchr( uri, '?' );
    314         if( pch )
    315             evbuffer_add_printf( buf, "%*.*s", (int)( pch - uri ),
    316                                  (int)( pch - uri ), uri );
    317         else
    318             evbuffer_add_printf( buf, "%s", uri );
    319     }
    320 
    321     if( strstr( (const char *)EVBUFFER_DATA( buf ), ".." ) )
    322         send_simple_response( req, 401, NULL );
    323     else
    324         serve_file( req, (const char *)EVBUFFER_DATA( buf ) );
    325 
    326     evbuffer_free( buf );
     308    subpath = tr_strdup( req->uri + 18 );
     309    if(( pch = strchr( subpath, '?' )))
     310        *pch = '\0';
     311
     312    filename = *subpath
     313        ? tr_strdup_printf( "%s%s%s", clutchDir, TR_PATH_DELIMITER_STR, subpath )
     314        : tr_strdup_printf( "%s%s%s", clutchDir, TR_PATH_DELIMITER_STR, "index.html" );
     315
     316    serve_file( req, filename );
     317
     318    tr_free( filename );
     319    tr_free( subpath );
    327320}
    328321
Note: See TracChangeset for help on using the changeset viewer.