From 6cb780fea59b7465533fa658ac249427bfc2f848 Mon Sep 17 00:00:00 2001 From: Shelikhoo Date: Sat, 28 Oct 2023 03:45:39 +0100 Subject: [PATCH] fix nil pointer deref at http upgrade transport hub --- transport/internet/httpupgrade/hub.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/transport/internet/httpupgrade/hub.go b/transport/internet/httpupgrade/hub.go index 174acac3a..ecbe441c1 100644 --- a/transport/internet/httpupgrade/hub.go +++ b/transport/internet/httpupgrade/hub.go @@ -34,6 +34,7 @@ func (s *server) Handle(conn net.Conn) (internet.Connection, error) { connection := strings.ToLower(req.Header.Get("Connection")) upgrade := strings.ToLower(req.Header.Get("Upgrade")) if connection != "upgrade" || upgrade != "websocket" { + _ = conn.Close() return nil, newError("unrecognized request") } resp := &http.Response{ @@ -48,6 +49,7 @@ func (s *server) Handle(conn net.Conn) (internet.Connection, error) { resp.Header.Set("Upgrade", "websocket") err = resp.Write(conn) if err != nil { + _ = conn.Close() return nil, err } return internet.Connection(conn), nil @@ -62,7 +64,6 @@ func (s *server) keepAccepting() { handledConn, err := s.Handle(conn) if err != nil { newError("failed to handle request").Base(err).WriteToLog() - common.Must(handledConn.Close()) continue } s.addConn(handledConn)