From ddf94a7b39ed49ad5b97ab264159ad4c3ed3517c Mon Sep 17 00:00:00 2001 From: Jordan Whited Date: Mon, 1 Jul 2024 16:07:48 -0700 Subject: [PATCH] cmd/stunstamp: fix handling of invalid DERP map resp (#12679) Updates tailscale/corp#20344 Signed-off-by: Jordan Whited --- cmd/stunstamp/stunstamp.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/cmd/stunstamp/stunstamp.go b/cmd/stunstamp/stunstamp.go index 6c009de46..a4d25922a 100644 --- a/cmd/stunstamp/stunstamp.go +++ b/cmd/stunstamp/stunstamp.go @@ -60,10 +60,13 @@ func getDERPMap(ctx context.Context, url string) (*tailcfg.DERPMap, error) { return nil, err } defer resp.Body.Close() + if resp.StatusCode != 200 { + return nil, fmt.Errorf("non-200 derp map resp: %d", resp.StatusCode) + } dm := tailcfg.DERPMap{} err = json.NewDecoder(resp.Body).Decode(&dm) if err != nil { - return nil, nil + return nil, fmt.Errorf("failed to decode derp map resp: %v", err) } return &dm, nil }