1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2025-03-19 02:05:32 +00:00

(trunk) #2938 "crash when adding a torrent by URL from an ftp source over RPC" -- fixed in trunk for 1.91

This commit is contained in:
Charles Kerr 2010-02-20 15:57:05 +00:00
parent a973e38bb5
commit 5a9a07b71e
8 changed files with 74 additions and 29 deletions

View file

@ -133,7 +133,7 @@ getHostName( const char * url )
int port = 0;
char * host = NULL;
char * ret;
tr_httpParseURL( url, strlen( url ), &host, &port, NULL );
tr_urlParse( url, strlen( url ), NULL, &host, &port, NULL );
ret = tr_strdup_printf( "%s:%d", ( host ? host : "invalid" ), port );
tr_free( host );
return ret;

View file

@ -380,7 +380,7 @@ tr_realMakeMetaInfo( tr_metainfo_builder * builder )
/* allow an empty set, but if URLs *are* listed, verify them. #814, #971 */
for( i = 0; i < builder->trackerCount && !builder->result; ++i ) {
if( !tr_httpIsValidURL( builder->trackers[i].announce ) ) {
if( !tr_urlIsValidTracker( builder->trackers[i].announce ) ) {
tr_strlcpy( builder->errfile, builder->trackers[i].announce,
sizeof( builder->errfile ) );
builder->result = TR_MAKEMETA_URL;

View file

@ -288,7 +288,7 @@ getannounce( tr_info * inf, tr_benc * meta )
if( tr_bencGetStr( tr_bencListChild( tier, j ), &str ) )
{
char * url = tr_strstrip( tr_strdup( str ) );
if( tr_httpIsValidURL( url ) )
if( tr_urlIsValidTracker( url ) )
{
tr_tracker_info * t = trackers + trackerCount;
t->tier = validTiers;
@ -320,7 +320,7 @@ getannounce( tr_info * inf, tr_benc * meta )
&& tr_bencDictFindStr( meta, "announce", &str ) )
{
char * url = tr_strstrip( tr_strdup( str ) );
if( tr_httpIsValidURL( url ) )
if( tr_urlIsValidTracker( url ) )
{
trackers = tr_new0( tr_tracker_info, 1 );
trackers[trackerCount].tier = 0;

View file

@ -2086,7 +2086,7 @@ tr_torrentSetAnnounceList( tr_torrent * tor,
/* look for bad URLs */
for( i=0; ok && i<trackerCount; ++i )
if( !tr_httpIsValidURL( trackers[i].announce ) )
if( !tr_urlIsValidTracker( trackers[i].announce ) )
ok = FALSE;
/* save to the .torrent file */

View file

@ -324,24 +324,29 @@ static int
test_url( void )
{
int port;
char * scheme;
char * host;
char * path;
char * str;
const char * url;
url = "http://www.some-tracker.org/some/path";
check( !tr_httpParseURL( url, -1, &host, &port, &path ) )
check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) )
check( !strcmp( scheme, "http" ) )
check( !strcmp( host, "www.some-tracker.org" ) )
check( !strcmp( path, "/some/path" ) )
check( port == 80 )
tr_free( scheme );
tr_free( path );
tr_free( host );
url = "http://www.some-tracker.org:80/some/path";
check( !tr_httpParseURL( url, -1, &host, &port, &path ) )
check( !tr_urlParse( url, -1, &scheme, &host, &port, &path ) )
check( !strcmp( scheme, "http" ) )
check( !strcmp( host, "www.some-tracker.org" ) )
check( !strcmp( path, "/some/path" ) )
check( port == 80 )
tr_free( scheme );
tr_free( path );
tr_free( host );

View file

@ -913,8 +913,8 @@ tr_hex_to_sha1( uint8_t * out, const char * in )
****
***/
tr_bool
tr_httpIsValidURL( const char * url )
static tr_bool
isValidURLChars( const char * url )
{
const char * c;
static const char * rfc2396_valid_chars =
@ -933,21 +933,55 @@ tr_httpIsValidURL( const char * url )
if( !strchr( rfc2396_valid_chars, *c ) )
return FALSE;
return tr_httpParseURL( url, -1, NULL, NULL, NULL ) == 0;
return TRUE;
}
tr_bool tr_addressIsIP( const char * address )
/** @brief return TRUE if the url is a http or https url that Transmission understands */
tr_bool
tr_urlIsValidTracker( const char * url )
{
tr_bool valid;
char * scheme = NULL;
valid = isValidURLChars( url )
&& !tr_urlParse( url, -1, &scheme, NULL, NULL, NULL )
&& ( scheme != NULL )
&& ( !strcmp(scheme,"http") || !strcmp(scheme,"https") );
tr_free( scheme );
return valid;
}
/** @brief return TRUE if the url is a http or https or ftp or sftp url that Transmission understands */
tr_bool
tr_urlIsValid( const char * url )
{
tr_bool valid;
char * scheme = NULL;
valid = isValidURLChars( url )
&& !tr_urlParse( url, -1, &scheme, NULL, NULL, NULL )
&& ( scheme != NULL )
&& ( !strcmp(scheme,"http") || !strcmp(scheme,"https") || !strcmp(scheme,"ftp") || !strcmp(scheme,"sftp") );
tr_free( scheme );
return valid;
}
tr_bool
tr_addressIsIP( const char * address )
{
tr_address tempAddr;
return tr_pton(address, &tempAddr) != NULL;
}
int
tr_httpParseURL( const char * url_in,
int len,
char ** setme_host,
int * setme_port,
char ** setme_path )
tr_urlParse( const char * url_in,
int len,
char ** setme_protocol,
char ** setme_host,
int * setme_port,
char ** setme_path )
{
int err;
int port = 0;
@ -984,17 +1018,20 @@ tr_httpParseURL( const char * url_in,
}
}
err = !host || !path || !protocol
|| ( strcmp( protocol, "http" ) && strcmp( protocol, "https" ) );
err = !host || !path || !protocol;
if( !err && !port )
{
if( !strcmp( protocol, "ftp" ) ) port = 21;
if( !strcmp( protocol, "sftp" ) ) port = 22;
if( !strcmp( protocol, "http" ) ) port = 80;
if( !strcmp( protocol, "https" ) ) port = 443;
}
if( !err )
{
if( setme_protocol ) *setme_protocol = tr_strdup( protocol );
if( setme_host ){ ( (char*)host )[-3] = ':'; *setme_host =
tr_strdup( host ); }
if( setme_path ){ if( path[0] == '/' ) *setme_path = tr_strdup( path );

View file

@ -436,20 +436,23 @@ void tr_sha1_to_hex( char * out, const uint8_t * sha1 ) TR_GNUC_NONNULL(1,2);
void tr_hex_to_sha1( uint8_t * out, const char * hex ) TR_GNUC_NONNULL(1,2);
/** @brief return TRUE if the url is a http, https, or ftp url that Transmission understands */
tr_bool tr_httpIsValidURL( const char * url ) TR_GNUC_NONNULL(1);
/** @brief convenience function to determine if an address is an IP address (IPv4 or IPv6) */
tr_bool tr_addressIsIP( const char * address );
/** @brief return TRUE if the url is a http or https url that Transmission understands */
tr_bool tr_urlIsValidTracker( const char * url ) TR_GNUC_NONNULL(1);
/** @brief return TRUE if the url is a [ http, https, ftp, ftps ] url that Transmission understands */
tr_bool tr_urlIsValid( const char * url ) TR_GNUC_NONNULL(1);
/** @brief parse a URL into its component parts
@return zero on success or an error number if an error occurred */
int tr_httpParseURL( const char * url,
int url_len,
char ** setme_host,
int * setme_port,
char ** setme_path ) TR_GNUC_NONNULL(1);
int tr_urlParse( const char * url,
int url_len,
char ** setme_scheme,
char ** setme_host,
int * setme_port,
char ** setme_path ) TR_GNUC_NONNULL(1);
/** @brief return TR_RATIO_NA, TR_RATIO_INF, or a number in [0..1]

View file

@ -207,7 +207,7 @@ dns_cache_lookup( struct tr_web_task * task, const char * host, const char ** re
static void
dns_cache_set_fail( struct tr_web_task * task, const char * host )
{
if( task->session->web != NULL )
if( ( task->session->web != NULL ) && ( host != NULL ) )
{
struct dns_cache_item * item;
tr_ptrArray * cache = &task->session->web->dns_cache;
@ -463,7 +463,7 @@ doDNS( void * vtask )
assert( task->resolved_host == NULL );
if( !tr_httpParseURL( task->url, -1, &host, &port, NULL ) )
if( !tr_urlParse( task->url, -1, NULL, &host, &port, NULL ) )
{
task->port = port;
task->host = host;