1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-06-12 10:50:43 +00:00

fix nil pointer deref at http upgrade transport hub

This commit is contained in:
Shelikhoo 2023-10-28 03:45:39 +01:00
parent bf7684c790
commit 6cb780fea5
No known key found for this signature in database
GPG Key ID: C4D5E79D22B25316

View File

@ -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)