mirror of
https://github.com/SagerNet/sing.git
synced 2025-04-03 03:47:38 +03:00
Fix buffer overflow
This commit is contained in:
parent
4e70523360
commit
b2828dac5f
4 changed files with 5 additions and 11 deletions
|
@ -199,7 +199,7 @@ func (b *Buffer) ReadAtLeastFrom(r io.Reader, min int) (int64, error) {
|
|||
}
|
||||
|
||||
func (b *Buffer) ReadFullFrom(r io.Reader, size int) (n int, err error) {
|
||||
if b.IsFull() {
|
||||
if b.end+size > b.Cap() {
|
||||
return 0, io.ErrShortBuffer
|
||||
}
|
||||
n, err = io.ReadFull(r, b.data[b.end:b.end+size])
|
||||
|
|
|
@ -36,10 +36,11 @@ func (c *ClientConn) ReadPacket(buffer *buf.Buffer) (M.Socksaddr, error) {
|
|||
if err != nil {
|
||||
return M.Socksaddr{}, err
|
||||
}
|
||||
if buffer.FreeLen() < int(length) {
|
||||
return M.Socksaddr{}, io.ErrShortBuffer
|
||||
_, err = buffer.ReadFullFrom(c, int(length))
|
||||
if err != nil {
|
||||
return M.Socksaddr{}, err
|
||||
}
|
||||
return destination, common.Error(buffer.ReadFullFrom(c, int(length)))
|
||||
return destination, nil
|
||||
}
|
||||
|
||||
func (c *ClientConn) WritePacket(buffer *buf.Buffer, destination M.Socksaddr) error {
|
||||
|
|
|
@ -68,9 +68,6 @@ func (c *ServerConn) loopInput() {
|
|||
break
|
||||
}
|
||||
buffer.FullReset()
|
||||
if int(length) > buffer.FreeLen() {
|
||||
break
|
||||
}
|
||||
_, err = buffer.ReadFullFrom(c.inputReader, int(length))
|
||||
if err != nil {
|
||||
break
|
||||
|
|
|
@ -288,10 +288,6 @@ func ReadPacket(conn net.Conn, buffer *buf.Buffer) (M.Socksaddr, error) {
|
|||
return M.Socksaddr{}, E.Cause(err, "read chunk length")
|
||||
}
|
||||
|
||||
if buffer.FreeLen() < int(length) {
|
||||
return M.Socksaddr{}, io.ErrShortBuffer
|
||||
}
|
||||
|
||||
err = rw.SkipN(conn, 2)
|
||||
if err != nil {
|
||||
return M.Socksaddr{}, E.Cause(err, "skip crlf")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue