mirror of
https://github.com/gravitational/teleport.git
synced 2026-10-12 02:15:01 +00:00
Read all PROXYv2 header bytes (#12861)
In PROXYv2 protocol there can be more bytes after IP/ports data that can be ignored but need to be consumed. This change handles that.
This commit is contained in:
@@ -28,6 +28,7 @@ import (
|
||||
"net"
|
||||
"strconv"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"github.com/gravitational/trace"
|
||||
)
|
||||
@@ -213,9 +214,11 @@ func ReadProxyLineV2(reader *bufio.Reader) (*ProxyLine, error) {
|
||||
if cmd != ProxyCommand {
|
||||
return nil, trace.BadParameter("unsupported command %d", cmd)
|
||||
}
|
||||
var size uint16
|
||||
switch header.Protocol {
|
||||
case ProtocolTCP4:
|
||||
var addr proxyV2Address4
|
||||
size = uint16(unsafe.Sizeof(addr))
|
||||
if err := binary.Read(reader, binary.BigEndian, &addr); err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
@@ -224,6 +227,7 @@ func ReadProxyLineV2(reader *bufio.Reader) (*ProxyLine, error) {
|
||||
ret.Destination = net.TCPAddr{IP: addr.Destination[:], Port: int(addr.DestinationPort)}
|
||||
case ProtocolTCP6:
|
||||
var addr proxyV2Address6
|
||||
size = uint16(unsafe.Sizeof(addr))
|
||||
if err := binary.Read(reader, binary.BigEndian, &addr); err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
@@ -234,5 +238,11 @@ func ReadProxyLineV2(reader *bufio.Reader) (*ProxyLine, error) {
|
||||
return nil, trace.BadParameter("unsupported protocol %x", header.Protocol)
|
||||
}
|
||||
|
||||
if header.Length > size {
|
||||
if _, err := io.CopyN(io.Discard, reader, int64(header.Length-size)); err != nil {
|
||||
return nil, trace.Wrap(err)
|
||||
}
|
||||
}
|
||||
|
||||
return &ret, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user