mirror of https://github.com/cbeuw/Cloak
Check buffer length for datagramBuffer.Read() in case the datagram is larger than the buffer
This commit is contained in:
parent
46c02d17f4
commit
8b99e419b3
|
|
@ -3,6 +3,7 @@
|
||||||
package multiplex
|
package multiplex
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"errors"
|
||||||
"io"
|
"io"
|
||||||
"sync"
|
"sync"
|
||||||
)
|
)
|
||||||
|
|
@ -39,9 +40,11 @@ func (d *datagramBuffer) Read(target []byte) (int, error) {
|
||||||
}
|
}
|
||||||
d.rwCond.Wait()
|
d.rwCond.Wait()
|
||||||
}
|
}
|
||||||
// TODO: return error if len(target) is smaller than the datagram
|
data := d.buf[0]
|
||||||
var data []byte
|
if len(target) < len(data) {
|
||||||
data, d.buf = d.buf[0], d.buf[1:]
|
return 0, errors.New("buffer is too small")
|
||||||
|
}
|
||||||
|
d.buf = d.buf[1:]
|
||||||
copy(target, data)
|
copy(target, data)
|
||||||
// err will always be nil because we have already verified that buf.Len() != 0
|
// err will always be nil because we have already verified that buf.Len() != 0
|
||||||
d.rwCond.Broadcast()
|
d.rwCond.Broadcast()
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue