mirror of https://github.com/v2ray/v2ray-core
remove extra bytes reading
parent
81c9743ce0
commit
64a3333987
|
@ -8,7 +8,6 @@ import (
|
|||
"v2ray.com/core/common"
|
||||
"v2ray.com/core/common/bitmask"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/dice"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
)
|
||||
|
@ -65,12 +64,7 @@ func ReadTCPSession(user *protocol.User, reader io.Reader) (*protocol.RequestHea
|
|||
buffer.Clear()
|
||||
|
||||
addr, port, err := addrParser.ReadAddressPort(buffer, br)
|
||||
|
||||
if err != nil {
|
||||
// Invalid address. Continue to read some bytes to confuse client.
|
||||
nBytes := dice.Roll(32) + 1
|
||||
buffer.Clear()
|
||||
buffer.AppendSupplier(buf.ReadFullFrom(br, int32(nBytes)))
|
||||
return nil, nil, newError("failed to read address").Base(err)
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,6 @@ import (
|
|||
"v2ray.com/core/common/bitmask"
|
||||
"v2ray.com/core/common/buf"
|
||||
"v2ray.com/core/common/crypto"
|
||||
"v2ray.com/core/common/dice"
|
||||
"v2ray.com/core/common/net"
|
||||
"v2ray.com/core/common/protocol"
|
||||
"v2ray.com/core/common/serial"
|
||||
|
@ -175,20 +174,6 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
|
|||
// 1 bytes reserved
|
||||
request.Command = protocol.RequestCommand(buffer.Byte(37))
|
||||
|
||||
var invalidRequestErr error
|
||||
defer func() {
|
||||
if invalidRequestErr != nil {
|
||||
randomLen := dice.Roll(64) + 1
|
||||
// Read random number of bytes for prevent detection.
|
||||
buffer.AppendSupplier(buf.ReadFullFrom(decryptor, int32(randomLen))) // nolint: errcheck
|
||||
}
|
||||
}()
|
||||
|
||||
if request.Security == protocol.SecurityType_UNKNOWN || request.Security == protocol.SecurityType_AUTO {
|
||||
invalidRequestErr = newError("unknown security type")
|
||||
return nil, invalidRequestErr
|
||||
}
|
||||
|
||||
switch request.Command {
|
||||
case protocol.RequestCommandMux:
|
||||
request.Address = net.DomainAddress("v1.mux.cool")
|
||||
|
@ -197,13 +182,7 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
|
|||
if addr, port, err := addrParser.ReadAddressPort(buffer, decryptor); err == nil {
|
||||
request.Address = addr
|
||||
request.Port = port
|
||||
} else {
|
||||
invalidRequestErr = newError("invalid address").Base(err)
|
||||
return nil, invalidRequestErr
|
||||
}
|
||||
default:
|
||||
invalidRequestErr = newError("invalid request command: ", request.Command)
|
||||
return nil, invalidRequestErr
|
||||
}
|
||||
|
||||
if padingLen > 0 {
|
||||
|
@ -229,6 +208,10 @@ func (s *ServerSession) DecodeRequestHeader(reader io.Reader) (*protocol.Request
|
|||
return nil, newError("invalid remote address")
|
||||
}
|
||||
|
||||
if request.Security == protocol.SecurityType_UNKNOWN || request.Security == protocol.SecurityType_AUTO {
|
||||
return nil, newError("unknown security type: ", request.Security)
|
||||
}
|
||||
|
||||
return request, nil
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue