Skip to content

Commit

Permalink
fix nil pointer deref at http upgrade transport hub
Browse files Browse the repository at this point in the history
  • Loading branch information
xiaokangwang committed Oct 28, 2023
1 parent bf7684c commit 6cb780f
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion transport/internet/httpupgrade/hub.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand All @@ -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
Expand All @@ -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)
Expand Down

0 comments on commit 6cb780f

Please sign in to comment.