From d3d4047da0f448354b7133c9ff2ea37fef9396fc Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Thu, 5 Jun 2008 16:25:22 +0000 Subject: [PATCH] fix handshake.c crash reported by wereHamster --- libtransmission/handshake.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/libtransmission/handshake.c b/libtransmission/handshake.c index 564961417..06ced31ec 100644 --- a/libtransmission/handshake.c +++ b/libtransmission/handshake.c @@ -228,9 +228,10 @@ parseHandshake( tr_handshake * handshake, /* torrent hash */ tr_peerIoReadBytes( handshake->io, inbuf, hash, sizeof(hash) ); - assert( tr_torrentExists( handshake->handle, hash ) ); assert( tr_peerIoHasTorrentHash( handshake->io ) ); - if( memcmp( hash, tr_peerIoGetTorrentHash(handshake->io), SHA_DIGEST_LENGTH ) ) { + if( !tr_torrentExists( handshake->handle, hash ) + || memcmp( hash, tr_peerIoGetTorrentHash(handshake->io), SHA_DIGEST_LENGTH ) ) + { dbgmsg( handshake, "peer returned the wrong hash. wtf?" ); return HANDSHAKE_BAD_TORRENT; }