From ece1bcc700122f9fc74ae50bffe9d7f7161a924b Mon Sep 17 00:00:00 2001 From: iaburton Date: Thu, 28 Mar 2019 13:04:50 -0500 Subject: [PATCH] fix tls.Config copy to properly handle embedded locks etc also move tls.Config clone after net.SplitHostPort closes #254 --- conn.go | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/conn.go b/conn.go index c1b31859..f4180a4d 100644 --- a/conn.go +++ b/conn.go @@ -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