about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRichard Nyberg <rnyberg@murmeldjur.se>2005-10-05 12:01:37 +0000
committerRichard Nyberg <rnyberg@murmeldjur.se>2005-10-05 12:01:37 +0000
commit2dc98c39b6034f11daafa74d92d86fd5e6beeb12 (patch)
tree62d4d2bd7e08e931896fff5a047325c21e8a41bd
parente982934f6b8de8f124c5a425ca29ebf323a109ee (diff)
downloadbtpd-2dc98c39b6034f11daafa74d92d86fd5e6beeb12.tar.gz
btpd-2dc98c39b6034f11daafa74d92d86fd5e6beeb12.zip
Fix two bugs. Add some logging.
-rw-r--r--btpd/net.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/btpd/net.c b/btpd/net.c
index 9958a3e..b6e47b8 100644
--- a/btpd/net.c
+++ b/btpd/net.c
@@ -146,7 +146,10 @@ net_dispatch_msg(struct peer *p, const char *buf)
 	peer_on_have(p, net_read32(buf));
 	break;
     case MSG_BITFIELD:
-	peer_on_bitfield(p, buf);
+        if (p->npieces == 0)
+            peer_on_bitfield(p, buf);
+        else
+            res = 1;
 	break;
     case MSG_REQUEST:
 	if ((p->flags & (PF_P_WANT|PF_I_CHOKE)) == PF_P_WANT) {
@@ -156,7 +159,9 @@ net_dispatch_msg(struct peer *p, const char *buf)
 	    if ((length > PIECE_BLOCKLEN
 		    || index >= p->tp->meta.npieces
 		    || !has_bit(p->tp->piece_field, index)
-		    || begin + length < torrent_piece_size(p->tp, index))) {
+		    || begin + length > torrent_piece_size(p->tp, index))) {
+                btpd_log(BTPD_L_MSG, "bad request: (%u, %u, %u) from %p\n",
+                         index, begin, length, p);
 		res = 1;
 		break;
 	    }
@@ -269,7 +274,8 @@ net_state(struct peer *p, const char *buf)
 
     return 0;
 bad:
-    btpd_log(BTPD_L_CONN, "bad data from %p.\n", p);
+    btpd_log(BTPD_L_CONN, "bad data from %p (%u, %u, %u).\n",
+             p, p->net.state, p->net.msg_len, p->net.msg_num);
     peer_kill(p);
     return -1;
 }