From a87566b9f6eec0168532a229cf99ada468fc27d0 Mon Sep 17 00:00:00 2001 From: Matt Joiner Date: Tue, 18 Nov 2014 21:54:53 -0600 Subject: [PATCH] dht: Handle truncated KRPC packets better, requires an update to bencode package --- dht/dht.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dht/dht.go b/dht/dht.go index fc703085..010489fc 100644 --- a/dht/dht.go +++ b/dht/dht.go @@ -278,7 +278,12 @@ func (s *Server) processPacket(b []byte, addr dHTAddr) { err := bencode.Unmarshal(b, &d) if err != nil { if se, ok := err.(*bencode.SyntaxError); !ok || se.Offset != 0 { - log.Printf("%s: received bad krpc message: %s: %q", s, err, b) + log.Printf("%s: received bad krpc message: %s%s", s, err, func() string { + if se.What == io.ErrUnexpectedEOF { + return "" + } + return fmt.Sprintf(": %q", b) + }()) } return } @@ -309,6 +314,10 @@ func (s *Server) serve() error { if err != nil { return err } + if n == len(b) { + logonce.Stderr.Printf("received dht packet exceeds buffer size") + continue + } s.processPacket(b[:n], newDHTAddr(addr.(*net.UDPAddr))) } }