derp/derphttp: fix data race and crash in proxy dial error path

Named result meant error paths assigned that variable to nil.
But a goroutine was concurrently using that variable.

Don't use a named result for that first parameter. Then then return
paths don't overwrite it.

Fixes #9129

Change-Id: Ie57f99d40ca8110085097780686d9bd620aaf160
Signed-off-by: Brad Fitzpatrick <bradfitz@tailscale.com>
pull/9137/head
Brad Fitzpatrick 1 year ago committed by Brad Fitzpatrick
parent 8ba07aac85
commit 3bce9632d9

@ -730,8 +730,9 @@ func firstStr(a, b string) string {
} }
// dialNodeUsingProxy connects to n using a CONNECT to the HTTP(s) proxy in proxyURL. // dialNodeUsingProxy connects to n using a CONNECT to the HTTP(s) proxy in proxyURL.
func (c *Client) dialNodeUsingProxy(ctx context.Context, n *tailcfg.DERPNode, proxyURL *url.URL) (proxyConn net.Conn, err error) { func (c *Client) dialNodeUsingProxy(ctx context.Context, n *tailcfg.DERPNode, proxyURL *url.URL) (_ net.Conn, err error) {
pu := proxyURL pu := proxyURL
var proxyConn net.Conn
if pu.Scheme == "https" { if pu.Scheme == "https" {
var d tls.Dialer var d tls.Dialer
proxyConn, err = d.DialContext(ctx, "tcp", net.JoinHostPort(pu.Hostname(), firstStr(pu.Port(), "443"))) proxyConn, err = d.DialContext(ctx, "tcp", net.JoinHostPort(pu.Hostname(), firstStr(pu.Port(), "443")))

Loading…
Cancel
Save