p2p/discover: copy buffer before sending read errors to unhandled (#34888)
Some checks are pending
/ Linux Build (push) Waiting to run
/ Linux Build (arm) (push) Waiting to run
/ Keeper Build (push) Waiting to run
/ Windows Build (push) Waiting to run
/ Docker Image (push) Waiting to run

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>
This commit is contained in:
cui 2026-05-07 21:18:04 +08:00 committed by GitHub
parent f7b7d4c7e5
commit e1e3eaa381
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -555,8 +555,9 @@ func (t *UDPv4) readLoop(unhandled chan<- ReadPacket) {
if err := t.handlePacket(from, buf[:nbytes]); err != nil && unhandled == nil { if err := t.handlePacket(from, buf[:nbytes]); err != nil && unhandled == nil {
t.log.Debug("Bad discv4 packet", "addr", from, "err", err) t.log.Debug("Bad discv4 packet", "addr", from, "err", err)
} else if err != nil && unhandled != nil { } else if err != nil && unhandled != nil {
p := ReadPacket{bytes.Clone(buf[:nbytes]), from}
select { select {
case unhandled <- ReadPacket{buf[:nbytes], from}: case unhandled <- p:
default: default:
} }
} }