fix(udp): check addr nil (close 1807)

This commit is contained in:
ksco.he 2022-06-07 21:36:37 +08:00 committed by yuhan6665
parent b67314796f
commit 76638d793c

View file

@ -8,6 +8,7 @@ import (
"encoding/gob"
"io"
"github.com/xtls/xray-core/common/errors"
"github.com/xtls/xray-core/common/net"
"github.com/xtls/xray-core/transport/internet"
)
@ -30,7 +31,14 @@ func ReadUDPMsg(conn *net.UDPConn, payload []byte, oob []byte) (int, int, int, *
nBytes, addr, err := conn.ReadFromUDP(payload)
var buf bytes.Buffer
enc := gob.NewEncoder(&buf)
enc.Encode(conn.LocalAddr().(*net.UDPAddr))
udpAddr, ok := conn.LocalAddr().(*net.UDPAddr)
if !ok {
return 0, 0, 0, nil, errors.New("invalid local address")
}
if addr == nil {
return 0, 0, 0, nil, errors.New("invalid remote address")
}
enc.Encode(udpAddr)
enc.Encode(addr)
var reader io.Reader = &buf
noob, _ := reader.Read(oob)