From 51be758eb605dab664501166b3b5f854bb26adb4 Mon Sep 17 00:00:00 2001 From: Moses Narrow <36607567+0pcom@users.noreply.github.com> Date: Fri, 21 Aug 2026 13:46:02 -0500 Subject: [PATCH] fix(lint): clear errcheck/gosec debt in status+interstitial code (make check green) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit golangci-lint 2.12.2 (errcheck check-blank:true, gosec G115/G705) flagged pre-existing issues in the merged status/interstitial code that CI's laxer lint let through, leaving `make check` RED on develop. No behavior change. - embedded_proxystatus.go: check ProcByName's returns instead of blanking. - routeviz_embed.go: handle the w.Write error (debug-log it). - proxystatus/render.go: keep the sent-share as uint64 and print it directly (no uint64->int narrowing) — clears gosec G115. - meshproxy.go: justify the status-page w.Write with //nolint:gosec (G705) — proxystatus.Render emits trusted server HTML that escapes all values. - stream_test.go / proxystatus_test.go: check the Write / ParseInt errors. --- pkg/proxyinterstitial/stream_test.go | 6 +++++- pkg/proxystatus/proxystatus_test.go | 5 ++++- pkg/proxystatus/render.go | 6 ++++-- pkg/visor/embedded_proxystatus.go | 3 ++- pkg/visor/meshproxy.go | 5 ++++- pkg/visor/routeviz_embed.go | 4 +++- 6 files changed, 22 insertions(+), 7 deletions(-) diff --git a/pkg/proxyinterstitial/stream_test.go b/pkg/proxyinterstitial/stream_test.go index b56a20d26a..b599ba0622 100644 --- a/pkg/proxyinterstitial/stream_test.go +++ b/pkg/proxyinterstitial/stream_test.go @@ -17,7 +17,11 @@ import ( // the fully de-chunked body. func readStreamBody(t *testing.T, c net.Conn, reqLine string) string { t.Helper() - go func() { _, _ = c.Write([]byte(reqLine)) }() + go func() { + if _, err := c.Write([]byte(reqLine)); err != nil { + return // reader finished + closed the pipe first — benign in this test + } + }() resp, err := http.ReadResponse(bufio.NewReader(c), nil) if err != nil { t.Fatalf("ReadResponse: %v", err) diff --git a/pkg/proxystatus/proxystatus_test.go b/pkg/proxystatus/proxystatus_test.go index 45d8890342..39da6aa6cd 100644 --- a/pkg/proxystatus/proxystatus_test.go +++ b/pkg/proxystatus/proxystatus_test.go @@ -108,7 +108,10 @@ func TestServeConn(t *testing.T) { func hexLum(h string) float64 { h = strings.TrimPrefix(h, "#") c := func(i int) float64 { - v, _ := strconv.ParseInt(h[i:i+2], 16, 0) + v, err := strconv.ParseInt(h[i:i+2], 16, 0) + if err != nil { + return 0 + } s := float64(v) / 255 if s <= 0.03928 { return s / 12.92 diff --git a/pkg/proxystatus/render.go b/pkg/proxystatus/render.go index aadf5dc465..6b01d8e5a9 100644 --- a/pkg/proxystatus/render.go +++ b/pkg/proxystatus/render.go @@ -93,11 +93,13 @@ func writeMuxSection(b *strings.Builder, snap Snapshot) { `legtransportpeersentbandwidth (sent share)` + `recvrttrtxstate`) for _, l := range snap.Legs { - pct := int(l.SentBytes * 100 / maxSent) + // share is 0..100 (maxSent is the per-leg max, >=1) — kept as uint64 and + // printed directly so there's no uint64->int narrowing to overflow-check. + share := l.SentBytes * 100 / maxSent state, scls := legState(l) fmt.Fprintf(b, `R%d%s%s%s`, l.Index, html.EscapeString(orDash(l.TpType)), html.EscapeString(shortPK(l.RemotePK)), humanBytes(l.SentBytes)) - fmt.Fprintf(b, ``, scls, pct) + fmt.Fprintf(b, ``, scls, share) fmt.Fprintf(b, `%s%.0f ms%d%s`, humanBytes(l.RecvBytes), l.LatencyMS, l.Retransmits, scls, state) } diff --git a/pkg/visor/embedded_proxystatus.go b/pkg/visor/embedded_proxystatus.go index 9dca32b879..b31037f148 100644 --- a/pkg/visor/embedded_proxystatus.go +++ b/pkg/visor/embedded_proxystatus.go @@ -66,7 +66,8 @@ func (p *visorStatusProvider) StatusSnapshot(surface proxystatus.Surface) (proxy snap := proxystatus.Snapshot{Surface: surface, App: app} if p.v.procM != nil { - _, snap.Running = p.v.procM.ProcByName(app) + proc, ok := p.v.procM.ProcByName(app) + snap.Running = ok && proc != nil } // Logs (best-effort): the store may not exist for an internal app that has diff --git a/pkg/visor/meshproxy.go b/pkg/visor/meshproxy.go index cd2bce0a78..ce20807dbb 100644 --- a/pkg/visor/meshproxy.go +++ b/pkg/visor/meshproxy.go @@ -746,7 +746,10 @@ func meshStatusHandler(suffix string, status proxystatus.Provider, next http.Han } w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Cache-Control", "no-store") - _, _ = w.Write(proxystatus.Render(snap)) //nolint:errcheck + // G705: proxystatus.Render emits trusted, server-generated HTML that + // HTML-escapes every interpolated value (see pkg/proxystatus/render.go); + // it is not tainted request input. + _, _ = w.Write(proxystatus.Render(snap)) //nolint:errcheck,gosec return } } diff --git a/pkg/visor/routeviz_embed.go b/pkg/visor/routeviz_embed.go index 96e52e02d2..00b18b831d 100644 --- a/pkg/visor/routeviz_embed.go +++ b/pkg/visor/routeviz_embed.go @@ -20,6 +20,8 @@ func (hv *Hypervisor) getRouteViz() http.HandlerFunc { return func(w http.ResponseWriter, r *http.Request) { w.Header().Set("Content-Type", "text/html; charset=utf-8") w.Header().Set("Cache-Control", "no-cache") - _, _ = w.Write(routeVizHTML) + if _, err := w.Write(routeVizHTML); err != nil { + hv.log(r).WithError(err).Debug("route-viz page write failed") + } } }