From f6431185b0cd196acbefdda9fec523ed4d408aed Mon Sep 17 00:00:00 2001 From: James Tucker Date: Fri, 22 Nov 2024 14:26:42 -0800 Subject: [PATCH] net/netmon: catch ParseRIB panic to gather buffer data Updates #14201 Updates golang/go#70528 Signed-off-by: James Tucker --- net/netmon/netmon_darwin.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/net/netmon/netmon_darwin.go b/net/netmon/netmon_darwin.go index cc6301125..a5096889b 100644 --- a/net/netmon/netmon_darwin.go +++ b/net/netmon/netmon_darwin.go @@ -56,7 +56,15 @@ func (m *darwinRouteMon) Receive() (message, error) { if err != nil { 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 debugRouteMessages { m.logf("read %d bytes (% 02x), failed to parse RIB: %v", n, m.buf[:n], err)