From b9e1c18578a6ea82db3e57ecbaa601bf9bd6130c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Thu, 13 Oct 2022 12:55:02 -0700 Subject: [PATCH] net/netcheck: fix crash in checkCaptivePortal If netcheck happens before there's a derpmap. This seems to only affect Headscale because it doesn't send a derpmap as early? Change-Id: I51e0dfca8e40623e04702bc9cc471770ca20d2c2 Signed-off-by: Brad Fitzpatrick (cherry picked from commit 9a264dac014f6d82c13222f762cf5a65a2d9a91b) --- net/netcheck/netcheck.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/net/netcheck/netcheck.go b/net/netcheck/netcheck.go index 519759deb..d1a55b091 100644 --- a/net/netcheck/netcheck.go +++ b/net/netcheck/netcheck.go @@ -1105,6 +1105,9 @@ func (c *Client) checkCaptivePortal(ctx context.Context, dm *tailcfg.DERPMap, pr } rids = append(rids, id) } + if len(rids) == 0 { + return false, nil + } preferredDERP = rids[rand.Intn(len(rids))] }