fix off-by-one that was uncovered by the new benc's stricter parsing.
This commit is contained in:
parent
df9bd1f713
commit
784e0babda
|
@ -214,6 +214,13 @@ testParse( void )
|
|||
tr_free( saved );
|
||||
tr_bencFree( &val );
|
||||
|
||||
end = NULL;
|
||||
snprintf( (char*)buf, sizeof( buf ), "d8:completei1e8:intervali1800e12:min intervali1800e5:peers0:e" );
|
||||
err = tr_bencLoad( buf, sizeof( buf ), &val, (char**)&end );
|
||||
check( !err );
|
||||
check( end == buf + strlen( (const char*)buf ) );
|
||||
tr_bencFree( &val );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -291,18 +291,18 @@ tr_bencParse( const void * buf_in,
|
|||
{
|
||||
const uint8_t * end;
|
||||
uint8_t * str;
|
||||
size_t strlen;
|
||||
size_t str_len;
|
||||
int err;
|
||||
benc_val_t * node;
|
||||
|
||||
if(( err = tr_bencParseStr( buf, bufend, &end, &str, &strlen )))
|
||||
if(( err = tr_bencParseStr( buf, bufend, &end, &str, &str_len )))
|
||||
return err;
|
||||
|
||||
node = getNode( top, parentStack, TYPE_STR );
|
||||
if( !node )
|
||||
return TR_ERROR;
|
||||
|
||||
tr_bencInitStr( node, str, strlen, 0 );
|
||||
tr_bencInitStr( node, str, str_len, 0 );
|
||||
buf = end;
|
||||
|
||||
if( tr_ptrArrayEmpty( parentStack ) )
|
||||
|
@ -796,6 +796,7 @@ printStringFunc( const benc_val_t * val, void * vdata )
|
|||
int ii;
|
||||
struct WalkPrint * data = vdata;
|
||||
printLeadingSpaces( data );
|
||||
fprintf( data->out, "string: " );
|
||||
for( ii = 0; val->val.s.i > ii; ii++ )
|
||||
{
|
||||
if( '\\' == val->val.s.s[ii] ) {
|
||||
|
@ -807,6 +808,7 @@ printStringFunc( const benc_val_t * val, void * vdata )
|
|||
fprintf( data->out, "\\x%02x", val->val.s.s[ii] );
|
||||
}
|
||||
}
|
||||
fprintf( data->out, "\n" );
|
||||
}
|
||||
static void
|
||||
printListBeginFunc( const benc_val_t * val UNUSED, void * vdata )
|
||||
|
|
|
@ -278,14 +278,7 @@ parseBencResponse( struct evhttp_request * req, benc_val_t * setme )
|
|||
{
|
||||
const unsigned char * body = EVBUFFER_DATA( req->input_buffer );
|
||||
const int bodylen = EVBUFFER_LENGTH( req->input_buffer );
|
||||
int ret = 1;
|
||||
int i;
|
||||
|
||||
for( i=0; ret && i<bodylen; ++i )
|
||||
if( !tr_bencLoad( body+i, bodylen-1, setme, NULL ) )
|
||||
ret = 0;
|
||||
|
||||
return ret;
|
||||
return tr_bencLoad( body, bodylen, setme, NULL );
|
||||
}
|
||||
|
||||
static const char*
|
||||
|
|
Loading…
Reference in New Issue