From: Matt Joiner Date: Mon, 16 May 2016 08:48:56 +0000 (+1000) Subject: Return an error from Torrent.setMetadataSize X-Git-Tag: v1.0.0~726 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=c0283d33140bf6dde207629f05cc70ec70f3b1ec;p=btrtrc.git Return an error from Torrent.setMetadataSize This should mean connections sending ridiculous metadata sizes get dropped. --- diff --git a/client.go b/client.go index 4b0d0ac4..e5daf8b5 100644 --- a/client.go +++ b/client.go @@ -1244,7 +1244,11 @@ func (cl *Client) connectionLoop(t *Torrent, c *connection) error { if !ok { log.Printf("bad metadata_size type: %T", metadata_sizeUntyped) } else { - t.setMetadataSize(metadata_size, cl) + err = t.setMetadataSize(metadata_size) + if err != nil { + err = fmt.Errorf("error setting metadata size to %d", metadata_size) + break + } } } if _, ok := c.PeerExtensionIDs["ut_metadata"]; ok { diff --git a/torrent.go b/torrent.go index 2f76ab93..7d027fae 100644 --- a/torrent.go +++ b/torrent.go @@ -275,14 +275,13 @@ func (t *Torrent) haveAllMetadataPieces() bool { } // TODO: Propagate errors to disconnect peer. -func (t *Torrent) setMetadataSize(bytes int64, cl *Client) { +func (t *Torrent) setMetadataSize(bytes int64) (err error) { if t.haveInfo() { // We already know the correct metadata size. return } if bytes <= 0 || bytes > 10000000 { // 10MB, pulled from my ass. - log.Printf("%s: received bad metadata size: %d", t, bytes) - return + return errors.New("bad size") } if t.metadataBytes != nil && len(t.metadataBytes) == int(bytes) { return @@ -292,7 +291,7 @@ func (t *Torrent) setMetadataSize(bytes int64, cl *Client) { for _, c := range t.conns { c.requestPendingMetadata() } - + return } // The current working name for the torrent. Either the name in the info dict,