mirror of
https://github.com/transmission/transmission
synced 2024-12-24 16:52:39 +00:00
more unit tests for bounds-checking on incomplete bencoded data
This commit is contained in:
parent
b98a927a9a
commit
d3047158be
1 changed files with 24 additions and 1 deletions
|
@ -3,7 +3,7 @@
|
|||
#include "bencode.h"
|
||||
#include "utils.h" /* tr_free */
|
||||
|
||||
#define VERBOSE 0
|
||||
#define VERBOSE 1
|
||||
|
||||
int test = 0;
|
||||
|
||||
|
@ -239,6 +239,29 @@ testParse( void )
|
|||
tr_free( saved );
|
||||
tr_bencFree( &val );
|
||||
|
||||
/* too many endings */
|
||||
end = NULL;
|
||||
snprintf( (char*)buf, sizeof( buf ), "leee" );
|
||||
err = tr_bencParse( buf, buf + sizeof( buf ), &val, &end );
|
||||
check( !err );
|
||||
check( end == buf + 2 );
|
||||
saved = tr_bencSave( &val, &len );
|
||||
check( !strcmp( saved, "le" ) );
|
||||
tr_free( saved );
|
||||
tr_bencFree( &val );
|
||||
|
||||
/* no ending */
|
||||
end = NULL;
|
||||
snprintf( (char*)buf, sizeof( buf ), "l1:a1:b1:c" );
|
||||
err = tr_bencParse( buf, buf + strlen( (char*)buf ), &val, &end );
|
||||
check( err );
|
||||
|
||||
/* incomplete string */
|
||||
end = NULL;
|
||||
snprintf( (char*)buf, sizeof( buf ), "1:" );
|
||||
err = tr_bencParse( buf, buf + strlen( (char*)buf ), &val, &end );
|
||||
check( err );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue