Skip to content

Commit e1e3eaa

Browse files
cuiweixiefjl
andauthored
p2p/discover: copy buffer before sending read errors to unhandled (#34888)
This fixes an issue where packets send to the `Unhandled` channel configured on discv4 could be corrupted when the packet buffer gets reused. --------- Co-authored-by: Felix Lange <fjl@twurst.com>
1 parent f7b7d4c commit e1e3eaa

1 file changed

Lines changed: 2 additions & 1 deletion

File tree

p2p/discover/v4_udp.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -555,8 +555,9 @@ func (t *UDPv4) readLoop(unhandled chan<- ReadPacket) {
555555
if err := t.handlePacket(from, buf[:nbytes]); err != nil && unhandled == nil {
556556
t.log.Debug("Bad discv4 packet", "addr", from, "err", err)
557557
} else if err != nil && unhandled != nil {
558+
p := ReadPacket{bytes.Clone(buf[:nbytes]), from}
558559
select {
559-
case unhandled <- ReadPacket{buf[:nbytes], from}:
560+
case unhandled <- p:
560561
default:
561562
}
562563
}

0 commit comments

Comments
 (0)