From 2c98c44d9a7c0b67aef7e72e7fed0766a7e7b1e6 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 23 Jan 2025 13:58:40 -0800 Subject: [PATCH] control/controlclient: sanitize invalid DERPMap nil Region from control Fixes #14752 Change-Id: If364603eefb9ac6dc5ec6df84a0d5e16c94dda8d Signed-off-by: Brad Fitzpatrick --- control/controlclient/map.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/control/controlclient/map.go b/control/controlclient/map.go index 1a54fc543..f0a11bdf1 100644 --- a/control/controlclient/map.go +++ b/control/controlclient/map.go @@ -300,6 +300,15 @@ func (ms *mapSession) updateStateFromResponse(resp *tailcfg.MapResponse) { if dm := resp.DERPMap; dm != nil { ms.vlogf("netmap: new map contains DERP map") + // Guard against the control server accidentally sending + // a nil region definition, which at least Headscale was + // observed to send. + for rid, r := range dm.Regions { + if r == nil { + delete(dm.Regions, rid) + } + } + // Zero-valued fields in a DERPMap mean that we're not changing // anything and are using the previous value(s). if ldm := ms.lastDERPMap; ldm != nil {