mirror of
https://github.com/transmission/transmission.git
synced 2026-05-08 09:39:08 +01:00
(libT) #1255: fails to parse announce URLs that have leading or trailing spaces
This commit is contained in:
+20
-15
@@ -263,14 +263,15 @@ getannounce( tr_info * inf, tr_benc * meta )
|
||||
tr_benc * tier = tr_bencListChild( tiers, i );
|
||||
const int tierSize = tr_bencListSize( tier );
|
||||
for( j=0; j<tierSize; ++j ) {
|
||||
const char * str;
|
||||
if( tr_bencGetStr( tr_bencListChild( tier, j ), &str )
|
||||
&& tr_httpIsValidURL( str ) ) {
|
||||
tr_tracker_info * t = trackers + trackerCount++;
|
||||
t->tier = i;
|
||||
t->announce = tr_strdup( str );
|
||||
t->scrape = announceToScrape( str );
|
||||
/*fprintf( stderr, "tier %d: %s\n", i, str );*/
|
||||
if( tr_bencGetStr( tr_bencListChild( tier, j ), &str ) ) {
|
||||
char * url = tr_strstrip( tr_strdup( str ) );
|
||||
if( tr_httpIsValidURL( url ) ) {
|
||||
tr_tracker_info * t = trackers + trackerCount++;
|
||||
t->tier = i;
|
||||
t->announce = tr_strdup( url );
|
||||
t->scrape = announceToScrape( url );
|
||||
}
|
||||
tr_free( url );
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -284,14 +285,18 @@ getannounce( tr_info * inf, tr_benc * meta )
|
||||
|
||||
/* Regular announce value */
|
||||
if( !trackerCount
|
||||
&& tr_bencDictFindStr( meta, "announce", &str )
|
||||
&& tr_httpIsValidURL( str ) )
|
||||
&& tr_bencDictFindStr( meta, "announce", &str ) )
|
||||
{
|
||||
trackers = tr_new0( tr_tracker_info, 1 );
|
||||
trackers[trackerCount].tier = 0;
|
||||
trackers[trackerCount].announce = tr_strdup( str );
|
||||
trackers[trackerCount++].scrape = announceToScrape( str );
|
||||
/*fprintf( stderr, "single announce: [%s]\n", str );*/
|
||||
char * url = tr_strstrip( tr_strdup( str ) );
|
||||
if( tr_httpIsValidURL( url ) )
|
||||
{
|
||||
trackers = tr_new0( tr_tracker_info, 1 );
|
||||
trackers[trackerCount].tier = 0;
|
||||
trackers[trackerCount].announce = tr_strdup( url );
|
||||
trackers[trackerCount++].scrape = announceToScrape( url );
|
||||
/*fprintf( stderr, "single announce: [%s]\n", url );*/
|
||||
}
|
||||
tr_free( url );
|
||||
}
|
||||
|
||||
inf->trackers = trackers;
|
||||
|
||||
@@ -85,6 +85,35 @@ test_bitfields( void )
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
test_strstrip( void )
|
||||
{
|
||||
char *in, *out;
|
||||
|
||||
/* strstrip */
|
||||
in = tr_strdup( " test " );
|
||||
out = tr_strstrip( in );
|
||||
check( in == out );
|
||||
check( !strcmp( in, "test" ) );
|
||||
tr_free( in );
|
||||
|
||||
/* strstrip */
|
||||
in = tr_strdup( " test test " );
|
||||
out = tr_strstrip( in );
|
||||
check( in == out );
|
||||
check( !strcmp( in, "test test" ) );
|
||||
tr_free( in );
|
||||
|
||||
/* strstrip */
|
||||
in = tr_strdup( "test" );
|
||||
out = tr_strstrip( in );
|
||||
check( in == out );
|
||||
check( !strcmp( in, "test" ) );
|
||||
tr_free( in );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
main( void )
|
||||
{
|
||||
@@ -106,6 +135,9 @@ main( void )
|
||||
tr_free( in );
|
||||
tr_free( out );
|
||||
|
||||
if(( i = test_strstrip( )))
|
||||
return i;
|
||||
|
||||
/* simple bitfield tests */
|
||||
for( l=0; l<NUM_LOOPS; ++l )
|
||||
if(( i = test_bitfields( )))
|
||||
|
||||
@@ -669,6 +669,34 @@ tr_strerror( int i )
|
||||
return ret;
|
||||
}
|
||||
|
||||
/****
|
||||
*****
|
||||
****/
|
||||
|
||||
char*
|
||||
tr_strstrip( char * str )
|
||||
{
|
||||
if( str != NULL )
|
||||
{
|
||||
size_t pos;
|
||||
size_t len = strlen( str );
|
||||
|
||||
while( len && isspace( str[len-1] ) )
|
||||
--len;
|
||||
str[len] = '\0';
|
||||
|
||||
for( pos=0; pos<len && isspace( str[pos] ); )
|
||||
++pos;
|
||||
|
||||
len -= pos;
|
||||
memmove( str, str+pos, len );
|
||||
str[len] = '\0';
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
|
||||
|
||||
/****
|
||||
*****
|
||||
****/
|
||||
|
||||
@@ -204,6 +204,8 @@ int tr_snprintf( char * buf, size_t buflen, const char * fmt, ... );
|
||||
|
||||
const char* tr_strerror( int );
|
||||
|
||||
char* tr_strstrip( char * str );
|
||||
|
||||
/***
|
||||
****
|
||||
***/
|
||||
|
||||
Reference in New Issue
Block a user