1
0
Fork 0
mirror of https://github.com/transmission/transmission synced 2024-12-26 09:37:56 +00:00

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

View file

@ -3,7 +3,7 @@
#include "bencode.h" #include "bencode.h"
#include "utils.h" /* tr_free */ #include "utils.h" /* tr_free */
#define VERBOSE 0 #define VERBOSE 1
int test = 0; int test = 0;
@ -239,6 +239,29 @@ testParse( void )
tr_free( saved ); tr_free( saved );
tr_bencFree( &val ); 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; return 0;
} }