(trunk libT) #2653 "transmission-remote-dotnet makes transmission-daemon segfault" -- fixed for 1.80

This commit is contained in:
Charles Kerr
2009-12-09 12:44:23 +00:00
parent fce52ac965
commit f73f223540
3 changed files with 27 additions and 19 deletions
+1 -1
View File
@@ -535,7 +535,7 @@ addField( const tr_torrent * tor, tr_benc * d, const char * key )
else if( tr_streq( key, keylen, "pieces" ) ) {
const tr_bitfield * pieces = tr_cpPieceBitfield( &tor->completion );
char * str = tr_base64_encode( pieces->bits, pieces->byteCount, NULL );
tr_bencDictAddStr( d, key, str );
tr_bencDictAddStr( d, key, str!=NULL ? str : "" );
tr_free( str );
}
else if( tr_streq( key, keylen, "pieceCount" ) )
+3
View File
@@ -345,6 +345,9 @@ main( void )
check( len == 5 );
tr_free( in );
tr_free( out );
out = tr_base64_encode( NULL, 0, &len );
check( out == NULL );
check( len == 0 );
if( ( i = test_hex( ) ) )
return i;
+23 -18
View File
@@ -1036,29 +1036,34 @@ tr_httpParseURL( const char * url_in,
#include <openssl/buffer.h>
char *
tr_base64_encode( const void * input,
int length,
int * setme_len )
tr_base64_encode( const void * input, int length, int * setme_len )
{
char * ret;
BIO * b64;
BIO * bmem;
BUF_MEM * bptr;
int retlen = 0;
char * ret = NULL;
if( length < 1 )
length = strlen( input );
if( input != NULL )
{
BIO * b64;
BIO * bmem;
BUF_MEM * bptr;
if( length < 1 )
length = strlen( input );
bmem = BIO_new( BIO_s_mem( ) );
b64 = BIO_new( BIO_f_base64( ) );
b64 = BIO_push( b64, bmem );
BIO_write( b64, input, length );
(void) BIO_flush( b64 );
BIO_get_mem_ptr( b64, &bptr );
ret = tr_strndup( bptr->data, bptr->length );
retlen = bptr->length;
BIO_free_all( b64 );
}
bmem = BIO_new( BIO_s_mem( ) );
b64 = BIO_new( BIO_f_base64( ) );
b64 = BIO_push( b64, bmem );
BIO_write( b64, input, length );
(void) BIO_flush( b64 );
BIO_get_mem_ptr( b64, &bptr );
ret = tr_strndup( bptr->data, bptr->length );
if( setme_len )
*setme_len = bptr->length;
*setme_len = retlen;
BIO_free_all( b64 );
return ret;
}