Skip to content

Commit

Permalink
fix tls.Config copy to properly handle embedded locks etc
Browse files Browse the repository at this point in the history
also move tls.Config clone after net.SplitHostPort

closes #254
  • Loading branch information
iaburton authored and ploxiln committed Dec 24, 2019
1 parent 5dd0672 commit ece1bcc
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -384,18 +384,19 @@ func (c *Conn) identify() (*IdentifyResponse, error) {
}

func (c *Conn) upgradeTLS(tlsConf *tls.Config) error {
// create a local copy of the config to set ServerName for this connection
var conf tls.Config
if tlsConf != nil {
conf = *tlsConf
}
host, _, err := net.SplitHostPort(c.addr)
if err != nil {
return err
}

// create a local copy of the config to set ServerName for this connection
conf := &tls.Config{}
if tlsConf != nil {
conf = tlsConf.Clone()
}
conf.ServerName = host

c.tlsConn = tls.Client(c.conn, &conf)
c.tlsConn = tls.Client(c.conn, conf)
err = c.tlsConn.Handshake()
if err != nil {
return err
Expand Down

0 comments on commit ece1bcc

Please sign in to comment.