From: Jordan Lee Date: Thu, 12 May 2011 06:43:40 +0000 (+0000) Subject: (trunk libT) fix magnet link crash in peer-msgs.c's updateDesiredRequestCount() repor... X-Git-Tag: 2.30~10 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=a4ab013568c1703caa15399658beb998f4c807c7;p=transmission (trunk libT) fix magnet link crash in peer-msgs.c's updateDesiredRequestCount() reported by quinx in the forums. In some odd cases (such as if unchoked without having shown interest), the code could dividing a number by the torrent's block size without checking to see if the torrent had its metadata yet. This caused a division by zero because a magnet torrent's blocksize is unset until the metadata is downloaded. --- diff --git a/libtransmission/peer-msgs.c b/libtransmission/peer-msgs.c index 899e71247..b8bdbabec 100644 --- a/libtransmission/peer-msgs.c +++ b/libtransmission/peer-msgs.c @@ -1663,15 +1663,11 @@ updateDesiredRequestCount( tr_peermsgs * msgs ) { const tr_torrent * const torrent = msgs->torrent; - if( tr_torrentIsSeed( msgs->torrent ) ) - { - msgs->desiredRequestCount = 0; - } - else if( msgs->peer->clientIsChoked ) - { - msgs->desiredRequestCount = 0; - } - else if( !msgs->peer->clientIsInterested ) + + /* there are lots of reasons we might not want to request any blocks... */ + if( tr_torrentIsSeed( torrent ) || !tr_torrentHasMetadata( torrent ) + || msgs->peer->clientIsChoked + || !msgs->peer->clientIsInterested ) { msgs->desiredRequestCount = 0; }