dht: Handle truncated KRPC packets better, requires an update to bencode package
This commit is contained in:
parent
e1f720c770
commit
a87566b9f6
11
dht/dht.go
11
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)))
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue