From e1d11c19bbb51d3efcc7a8230596b500ddc02ae6 Mon Sep 17 00:00:00 2001 From: Vasiliy Tolstov Date: Mon, 29 Jun 2020 14:03:56 +0300 Subject: [PATCH] additional check for nil conn Signed-off-by: Vasiliy Tolstov --- client.go | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/client.go b/client.go index 5150258..1d6a8e6 100644 --- a/client.go +++ b/client.go @@ -22,6 +22,10 @@ var ( // Connect handshake with remote server using underlining net.Conn func Connect(ctx context.Context, c net.Conn, cfg *ClientConfig) (*ClientConn, error) { + if c == nil { + return nil, fmt.Errorf("passed invalid net.Conn") + } + conn, err := NewClientConn(c, cfg) if err != nil { conn.Close() @@ -220,6 +224,7 @@ func NewClientConn(c net.Conn, cfg *ClientConfig) (*ClientConn, error) { if len(cfg.Encodings) == 0 { return nil, fmt.Errorf("client can't handle encodings") } + return &ClientConn{ c: c, cfg: cfg,