From c39d3db7a036cdcce44ed020e10574edb2a466a7 Mon Sep 17 00:00:00 2001 From: Harshavardhana Date: Tue, 23 Aug 2016 00:20:15 -0700 Subject: [PATCH] server/tls: allocate tls.Config{} properly. (#2537) There is a golang bug which crashes the server, allocate tls.Config properly to avoid this problem. ``` 2016/08/22 20:21:03 http: panic serving 127.0.0.1:40744: runtime error: invalid memory address or nil pointer dereference goroutine 38 [running]: net/http.(*conn).serve.func1(0xc820526680) /home/harsha/.gimme/versions/go1.6.2.linux.amd64/src/net/http/server.go:1389 +0xc1 panic(0xbefa80, 0xc820010140) /home/harsha/.gimme/versions/go1.6.2.linux.amd64/src/runtime/panic.go:443 +0x4e9 crypto/tls.(*Conn).serverHandshake(0xc820368300, 0x0, 0x0) /home/harsha/.gimme/versions/go1.6.2.linux.amd64/src/crypto/tls/handshake_server.go:43 +0x4d6 crypto/tls.(*Conn).Handshake(0xc820368300, 0x0, 0x0) /home/harsha/.gimme/versions/go1.6.2.linux.amd64/src/crypto/tls/conn.go:1035 +0x169 net/http.(*conn).serve(0xc820526680) /home/harsha/.gimme/versions/go1.6.2.linux.amd64/src/net/http/server.go:1405 +0x382 created by net/http.(*Server).Serve /home/harsha/.gimme/versions/go1.6.2.linux.amd64/src/net/http/server.go:2137 +0x44e ``` Fixes #2536 --- cmd/server-mux.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/cmd/server-mux.go b/cmd/server-mux.go index 40ba94bfc..3ea309a6c 100644 --- a/cmd/server-mux.go +++ b/cmd/server-mux.go @@ -130,11 +130,8 @@ type MuxListener struct { // or invalid func NewMuxListener(listener net.Listener, wg *sync.WaitGroup, certPath, keyPath string) (*MuxListener, error) { var err error - var config *tls.Config - config = nil - - if certPath != "" { - config = &tls.Config{} + config := &tls.Config{} // Always instantiate. + if certPath != "" && keyPath != "" { if config.NextProtos == nil { config.NextProtos = []string{"http/1.1", "h2"} }