Revise the Code per XTLS#1515 (#1536)

* Use buf.FromBytes(make([]byte, 0, buf.Size)) to create `first`

Fixes https://github.com/XTLS/Xray-core/issues/1515

* Update server.go

* Update inbound.go

Co-authored-by: RPRX <63339210+RPRX@users.noreply.github.com>
This commit is contained in:
MP 2023-01-17 11:18:58 +08:00 committed by GitHub
parent 7added2693
commit 77d2f9edd7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 6 deletions

View file

@ -155,9 +155,8 @@ func (s *Server) Process(ctx context.Context, network net.Network, conn stat.Con
return newError("unable to set read deadline").Base(err).AtWarning()
}
first := buf.New()
defer first.Release()
first := buf.FromBytes(make([]byte, buf.Size))
first.Clear()
firstLen, err := first.ReadFrom(conn)
if err != nil {
return newError("failed to read first request").Base(err)

View file

@ -188,9 +188,8 @@ func (h *Handler) Process(ctx context.Context, network net.Network, connection s
return newError("unable to set read deadline").Base(err).AtWarning()
}
first := buf.New()
defer first.Release()
first := buf.FromBytes(make([]byte, buf.Size))
first.Clear()
firstLen, _ := first.ReadFrom(connection)
newError("firstLen = ", firstLen).AtInfo().WriteToLog(sid)