]> granicus.if.org Git - transmission/commitdiff
(trunk libT) fix magnet link crash in peer-msgs.c's updateDesiredRequestCount() repor...
authorJordan Lee <jordan@transmissionbt.com>
Thu, 12 May 2011 06:43:40 +0000 (06:43 +0000)
committerJordan Lee <jordan@transmissionbt.com>
Thu, 12 May 2011 06:43:40 +0000 (06:43 +0000)
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.

libtransmission/peer-msgs.c

index 899e712479b894e774018b0dcd5f7fb6cbc3b426..b8bdbabec9fece8836019e4bd971b11d2af62706 100644 (file)
@@ -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;
     }