From f37da42a8c5d0b2502b22bb28c9a46a375409059 Mon Sep 17 00:00:00 2001 From: Jordan Lee Date: Tue, 5 Apr 2011 22:21:18 +0000 Subject: [PATCH] (trunk libT) fix ABR error when parsing a URL with no path and no trailing slash after the host. Error reported by livings124 --- libtransmission/utils-test.c | 10 ++++++++++ libtransmission/utils.c | 6 ++++-- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/libtransmission/utils-test.c b/libtransmission/utils-test.c index fec13b2d0..f163ce225 100644 --- a/libtransmission/utils-test.c +++ b/libtransmission/utils-test.c @@ -385,6 +385,16 @@ test_url( void ) char * str; const char * url; + url = "http://1"; + check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) ); + check( !strcmp( scheme, "http" ) ) + check( !strcmp( host, "1" ) ) + check( !strcmp( path, "/" ) ) + check( port == 80 ) + tr_free( scheme ); + tr_free( path ); + tr_free( host ); + url = "http://www.some-tracker.org/some/path"; check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) ) check( !strcmp( scheme, "http" ) ) diff --git a/libtransmission/utils.c b/libtransmission/utils.c index 1e12a1daf..262059202 100644 --- a/libtransmission/utils.c +++ b/libtransmission/utils.c @@ -1030,7 +1030,8 @@ tr_urlParse( const char * url_in, host = pch; host_len = n; pch += n; - *pch++ = '\0'; + if( pch && *pch ) + *pch++ = '\0'; /*fprintf( stderr, "host is [%s]... what's left is [%s]\n", host, pch );*/ if( havePort ) { @@ -1061,7 +1062,8 @@ tr_urlParse( const char * url_in, if( setme_host ){ ( (char*)host )[-3] = ':'; *setme_host = tr_strndup( host, host_len ); } - if( setme_path ){ if( path[0] == '/' ) *setme_path = tr_strdup( path ); + if( setme_path ){ if( !*path ) *setme_path = tr_strdup( "/" ); + else if( path[0] == '/' ) *setme_path = tr_strdup( path ); else { ( (char*)path )[-1] = '/'; *setme_path = tr_strdup( path - 1 ); } } if( setme_port ) *setme_port = port; }