more unit tests for bounds-checking on incomplete bencoded data

This commit is contained in:
Charles Kerr 2008-02-01 21:53:01 +00:00
parent b98a927a9a
commit d3047158be
1 changed files with 24 additions and 1 deletions

View File

@ -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;
}