Browse Source

simplify NewSize calls

pull/985/head
Darien Raymond 7 years ago
parent
commit
1cbfeea0cd
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
  1. 7
      app/proxyman/mux/reader.go
  2. 7
      common/crypto/auth.go
  3. 20
      proxy/shadowsocks/ota.go

7
app/proxyman/mux/reader.go

@ -51,12 +51,7 @@ func (r *PacketReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
return nil, err
}
var b *buf.Buffer
if size <= buf.Size {
b = buf.New()
} else {
b = buf.NewSize(uint32(size))
}
b := buf.NewSize(uint32(size))
if err := b.AppendSupplier(buf.ReadFullFrom(r.reader, int(size))); err != nil {
b.Release()
return nil, err

7
common/crypto/auth.go

@ -124,12 +124,7 @@ func (r *AuthenticationReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
return nil, io.EOF
}
var b *buf.Buffer
if size <= buf.Size {
b = buf.New()
} else {
b = buf.NewSize(uint32(size))
}
b := buf.NewSize(uint32(size))
if err := b.Reset(buf.ReadFullFrom(r.reader, size)); err != nil {
b.Release()
return nil, err

20
proxy/shadowsocks/ota.go

@ -70,22 +70,14 @@ func NewChunkReader(reader io.Reader, auth *Authenticator) *ChunkReader {
}
func (v *ChunkReader) ReadMultiBuffer() (buf.MultiBuffer, error) {
buffer := buf.New()
if err := buffer.AppendSupplier(buf.ReadFullFrom(v.reader, 2)); err != nil {
buffer.Release()
return nil, err
}
// There is a potential buffer overflow here. Large buffer is 64K bytes,
// while uin16 + 10 will be more than that
length := serial.BytesToUint16(buffer.BytesTo(2)) + AuthSize
if length > buf.Size {
// Theoretically the size of a chunk is 64K, but most Shadowsocks implementations used <4K buffer.
buffer.Release()
buffer = buf.NewSize(uint32(length) + 128)
size, err := serial.ReadUint16(v.reader)
if err != nil {
return nil, newError("failed to read size")
}
size += AuthSize
buffer.Clear()
if err := buffer.AppendSupplier(buf.ReadFullFrom(v.reader, int(length))); err != nil {
buffer := buf.NewSize(uint32(size))
if err := buffer.AppendSupplier(buf.ReadFullFrom(v.reader, int(size))); err != nil {
buffer.Release()
return nil, err
}

Loading…
Cancel
Save