From 9108794362c31aafce945906d2049dbe132fa163 Mon Sep 17 00:00:00 2001 From: Andy Wang Date: Wed, 23 Dec 2020 17:42:54 +0000 Subject: [PATCH] Fix race condition in allocating obfsBuf --- internal/multiplex/stream.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/internal/multiplex/stream.go b/internal/multiplex/stream.go index d827117..90d5c16 100644 --- a/internal/multiplex/stream.go +++ b/internal/multiplex/stream.go @@ -174,9 +174,11 @@ func (s *Stream) Write(in []byte) (n int, err error) { // ReadFrom continuously read data from r and send it off, until either r returns error or nothing has been read // for readFromTimeout amount of time func (s *Stream) ReadFrom(r io.Reader) (n int64, err error) { + s.writingM.Lock() if s.obfsBuf == nil { s.obfsBuf = make([]byte, s.session.StreamSendBufferSize) } + s.writingM.Unlock() for { if s.readFromTimeout != 0 { if rder, ok := r.(net.Conn); !ok {