1 Description: fix denial of service and possible code execution via
2 overflow in tr_bitfieldEnsureNthBitAlloced
3 Origin: upstream, https://trac.transmissionbt.com/changeset/14303
5 Index: transmission-2.51/libtransmission/bitfield.c
6 ===================================================================
7 --- transmission-2.51.orig/libtransmission/bitfield.c 2014-07-11 14:16:10.232959680 -0400
8 +++ transmission-2.51/libtransmission/bitfield.c 2014-07-11 14:17:20.168958596 -0400
11 get_bytes_needed( size_t bit_count )
13 - return ( bit_count + 7u ) / 8u;
14 + return (bit_count >> 3) + (bit_count & 7 ? 1 : 0);
24 tr_bitfieldEnsureNthBitAlloced( tr_bitfield * b, size_t nth )
26 /* count is zero-based, so we need to allocate nth+1 bits before setting the nth */
28 + if (nth == SIZE_MAX)
31 tr_bitfieldEnsureBitsAlloced( b, nth + 1 );
38 tr_bitfieldAdd( tr_bitfield * b, size_t nth )
40 - if( !tr_bitfieldHas( b, nth ) )
41 + if (!tr_bitfieldHas (b, nth) && tr_bitfieldEnsureNthBitAlloced (b, nth))
43 - tr_bitfieldEnsureNthBitAlloced( b, nth );
44 b->bits[nth >> 3u] |= ( 0x80 >> ( nth & 7u ) );
45 tr_bitfieldIncTrueCount( b, 1 );
49 em = 0xff << ( 7 - ( end & 7 ) );
51 - tr_bitfieldEnsureNthBitAlloced( b, end );
52 + if (!tr_bitfieldEnsureNthBitAlloced (b, end))
57 b->bits[sb] |= ( sm & em );
60 assert( tr_bitfieldIsValid( b ) );
62 - if( !tr_bitfieldHas( b, nth ) )
63 + if (!tr_bitfieldHas (b, nth) && tr_bitfieldEnsureNthBitAlloced (b, nth))
65 - tr_bitfieldEnsureNthBitAlloced( b, nth );
66 b->bits[nth >> 3u] &= ( 0xff7f >> ( nth & 7u ) );
67 tr_bitfieldIncTrueCount( b, -1 );
71 em = ~( 0xff << ( 7 - ( end & 7 ) ) );
73 - tr_bitfieldEnsureNthBitAlloced( b, end );
74 + if (!tr_bitfieldEnsureNthBitAlloced (b, end))
79 b->bits[sb] &= ( sm | em );
80 Index: transmission-2.51/libtransmission/peer-msgs.c
81 ===================================================================
82 --- transmission-2.51.orig/libtransmission/peer-msgs.c 2014-07-11 14:16:10.232959680 -0400
83 +++ transmission-2.51/libtransmission/peer-msgs.c 2014-07-11 14:16:10.228959680 -0400
89 + #define EBADMSG EINVAL
95 @@ -1559,6 +1563,12 @@
99 + if (!requestIsValid (msgs, req)) {
100 + dbgmsg (msgs, "dropping invalid block %u:%u->%u",
101 + req->index, req->offset, req->length);
105 if( req->length != tr_torBlockCountBytes( msgs->torrent, block ) ) {
106 dbgmsg( msgs, "wrong block size -- expected %u, got %d",
107 tr_torBlockCountBytes( msgs->torrent, block ), req->length );