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))) } }