net/netmon: catch ParseRIB panic to gather buffer data

Updates #14201
Updates golang/go#70528

Signed-off-by: James Tucker <james@tailscale.com>
This commit is contained in:
James Tucker 2024-11-22 14:26:42 -08:00 committed by James Tucker
parent 36b7449fea
commit f6431185b0

View File

@ -56,7 +56,15 @@ func (m *darwinRouteMon) Receive() (message, error) {
if err != nil { if err != nil {
return nil, err return nil, err
} }
msgs, err := route.ParseRIB(route.RIBTypeRoute, m.buf[:n]) msgs, err := func() (msgs []route.Message, err error) {
defer func() {
if recover() != nil {
msgs = nil
err = fmt.Errorf("panic parsing route message")
}
}()
return route.ParseRIB(route.RIBTypeRoute, m.buf[:n])
}()
if err != nil { if err != nil {
if debugRouteMessages { if debugRouteMessages {
m.logf("read %d bytes (% 02x), failed to parse RIB: %v", n, m.buf[:n], err) m.logf("read %d bytes (% 02x), failed to parse RIB: %v", n, m.buf[:n], err)