From: Matt Joiner Date: Mon, 3 Aug 2015 15:17:32 +0000 (+1000) Subject: Fix crash if peer sends out of bounds HAVE message X-Git-Tag: v1.0.0~1087 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=f3317322f83a556d661a697c0290a02bd50fe0e7;p=btrtrc.git Fix crash if peer sends out of bounds HAVE message --- diff --git a/client.go b/client.go index efa41e2c..9469096f 100644 --- a/client.go +++ b/client.go @@ -1249,7 +1249,7 @@ func (t *torrent) initRequestOrdering(c *connection) { } } -func (me *Client) peerGotPiece(t *torrent, c *connection, piece int) { +func (me *Client) peerGotPiece(t *torrent, c *connection, piece int) error { if !c.peerHasAll { if t.haveInfo() { if c.PeerPieces == nil { @@ -1260,12 +1260,16 @@ func (me *Client) peerGotPiece(t *torrent, c *connection, piece int) { c.PeerPieces = append(c.PeerPieces, false) } } + if piece >= len(c.PeerPieces) { + return errors.New("peer got out of range piece index") + } c.PeerPieces[piece] = true } if t.wantPiece(piece) { t.connPendPiece(c, piece) me.replenishConnRequests(t, c) } + return nil } func (me *Client) peerUnchoked(torrent *torrent, conn *connection) {