Ignore:
Timestamp:
Feb 1, 2008, 9:53:01 PM (14 years ago)
Author:
charles
Message:

more unit tests for bounds-checking on incomplete bencoded data

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/libtransmission/bencode-test.c

    r4894 r4895  
    44#include "utils.h" /* tr_free */
    55
    6 #define VERBOSE 0
     6#define VERBOSE 1
    77
    88int test = 0;
     
    240240    tr_bencFree( &val );
    241241
     242    /* too many endings */
     243    end = NULL;
     244    snprintf( (char*)buf, sizeof( buf ), "leee" );
     245    err = tr_bencParse( buf, buf + sizeof( buf ), &val, &end );
     246    check( !err );
     247    check( end == buf + 2 );
     248    saved = tr_bencSave( &val, &len );
     249    check( !strcmp( saved, "le" ) );
     250    tr_free( saved );
     251    tr_bencFree( &val );
     252
     253    /* no ending */
     254    end = NULL;
     255    snprintf( (char*)buf, sizeof( buf ), "l1:a1:b1:c" );
     256    err = tr_bencParse( buf, buf + strlen( (char*)buf ), &val, &end );
     257    check( err );
     258
     259    /* incomplete string */
     260    end = NULL;
     261    snprintf( (char*)buf, sizeof( buf ), "1:" );
     262    err = tr_bencParse( buf, buf + strlen( (char*)buf ), &val, &end );
     263    check( err );
     264
    242265    return 0;
    243266}
Note: See TracChangeset for help on using the changeset viewer.