From 9c8bbc7888d8886e1b47d1bf1fec151eecfd2b4d Mon Sep 17 00:00:00 2001 From: Colin Adler Date: Wed, 8 Jun 2022 19:22:16 -0500 Subject: [PATCH] wgengine/magicsock: fix panic in http debug server Fixes an panic in `(*magicsock.Conn).ServeHTTPDebug` when the `recentPongs` ring buffer for an endpoint wraps around. Signed-off-by: Colin Adler --- wgengine/magicsock/debughttp.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/wgengine/magicsock/debughttp.go b/wgengine/magicsock/debughttp.go index 89164f21e..efdf01d96 100644 --- a/wgengine/magicsock/debughttp.go +++ b/wgengine/magicsock/debughttp.go @@ -172,6 +172,11 @@ func printEndpointHTML(w io.Writer, ep *endpoint) { break } pos := (int(s.recentPong) - i) % len(s.recentPongs) + // If s.recentPongs wraps around pos will be negative, so start + // again from the end of the slice. + if pos < 0 { + pos += len(s.recentPongs) + } pr := s.recentPongs[pos] fmt.Fprintf(w, "
  • pong %v ago: in %v, from %v src %v
  • \n", fmtMono(pr.pongAt), pr.latency.Round(time.Millisecond/10),