1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00
This commit is contained in:
Darien Raymond 2018-12-02 19:40:43 +01:00
parent e5314cfb56
commit c5a384195a
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169

View File

@ -35,7 +35,7 @@ func wrapSysConn(rawConn net.PacketConn, config *Config) (*sysConn, error) {
}, nil
}
var errCipherError = errors.New("cipher error")
var errInvalidPacket = errors.New("invalid packet")
func (c *sysConn) readFromInternal(p []byte) (int, net.Addr, error) {
buffer := getBuffer()
@ -48,6 +48,9 @@ func (c *sysConn) readFromInternal(p []byte) (int, net.Addr, error) {
payload := buffer[:nBytes]
if c.header != nil {
if len(payload) <= int(c.header.Size()) {
return 0, nil, errInvalidPacket
}
payload = payload[c.header.Size():]
}
@ -56,12 +59,16 @@ func (c *sysConn) readFromInternal(p []byte) (int, net.Addr, error) {
return n, addr, nil
}
if len(payload) <= c.auth.NonceSize() {
return 0, nil, errInvalidPacket
}
nonce := payload[:c.auth.NonceSize()]
payload = payload[c.auth.NonceSize():]
p, err = c.auth.Open(p[:0], nonce, payload, nil)
if err != nil {
return 0, nil, errCipherError
return 0, nil, errInvalidPacket
}
return len(p), addr, nil
@ -74,7 +81,7 @@ func (c *sysConn) ReadFrom(p []byte) (int, net.Addr, error) {
for {
n, addr, err := c.readFromInternal(p)
if err != nil && err != errCipherError {
if err != nil && err != errInvalidPacket {
return 0, nil, err
}
if err == nil {