cmd/stunstamp: fix handling of invalid DERP map resp (#12679)

Updates tailscale/corp#20344

Signed-off-by: Jordan Whited <jordan@tailscale.com>
This commit is contained in:
Jordan Whited 2024-07-01 16:07:48 -07:00 committed by GitHub
parent b56058d7e3
commit ddf94a7b39
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -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
}