mirror of
https://github.com/v2fly/v2ray-core.git
synced 2024-12-22 01:57:12 -05:00
fix #1451
This commit is contained in:
parent
e5314cfb56
commit
c5a384195a
@ -35,7 +35,7 @@ func wrapSysConn(rawConn net.PacketConn, config *Config) (*sysConn, error) {
|
|||||||
}, nil
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
var errCipherError = errors.New("cipher error")
|
var errInvalidPacket = errors.New("invalid packet")
|
||||||
|
|
||||||
func (c *sysConn) readFromInternal(p []byte) (int, net.Addr, error) {
|
func (c *sysConn) readFromInternal(p []byte) (int, net.Addr, error) {
|
||||||
buffer := getBuffer()
|
buffer := getBuffer()
|
||||||
@ -48,6 +48,9 @@ func (c *sysConn) readFromInternal(p []byte) (int, net.Addr, error) {
|
|||||||
|
|
||||||
payload := buffer[:nBytes]
|
payload := buffer[:nBytes]
|
||||||
if c.header != nil {
|
if c.header != nil {
|
||||||
|
if len(payload) <= int(c.header.Size()) {
|
||||||
|
return 0, nil, errInvalidPacket
|
||||||
|
}
|
||||||
payload = payload[c.header.Size():]
|
payload = payload[c.header.Size():]
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,12 +59,16 @@ func (c *sysConn) readFromInternal(p []byte) (int, net.Addr, error) {
|
|||||||
return n, addr, nil
|
return n, addr, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if len(payload) <= c.auth.NonceSize() {
|
||||||
|
return 0, nil, errInvalidPacket
|
||||||
|
}
|
||||||
|
|
||||||
nonce := payload[:c.auth.NonceSize()]
|
nonce := payload[:c.auth.NonceSize()]
|
||||||
payload = payload[c.auth.NonceSize():]
|
payload = payload[c.auth.NonceSize():]
|
||||||
|
|
||||||
p, err = c.auth.Open(p[:0], nonce, payload, nil)
|
p, err = c.auth.Open(p[:0], nonce, payload, nil)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return 0, nil, errCipherError
|
return 0, nil, errInvalidPacket
|
||||||
}
|
}
|
||||||
|
|
||||||
return len(p), addr, nil
|
return len(p), addr, nil
|
||||||
@ -74,7 +81,7 @@ func (c *sysConn) ReadFrom(p []byte) (int, net.Addr, error) {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
n, addr, err := c.readFromInternal(p)
|
n, addr, err := c.readFromInternal(p)
|
||||||
if err != nil && err != errCipherError {
|
if err != nil && err != errInvalidPacket {
|
||||||
return 0, nil, err
|
return 0, nil, err
|
||||||
}
|
}
|
||||||
if err == nil {
|
if err == nil {
|
||||||
|
Loading…
Reference in New Issue
Block a user