From 76638d793c4b48aa863e4ecc17c4a3b6b2915a4f Mon Sep 17 00:00:00 2001 From: "ksco.he" Date: Tue, 7 Jun 2022 21:36:37 +0800 Subject: [PATCH] fix(udp): check addr nil (close 1807) --- transport/internet/udp/hub_freebsd.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/transport/internet/udp/hub_freebsd.go b/transport/internet/udp/hub_freebsd.go index f9f2bf89..6bf9fd87 100644 --- a/transport/internet/udp/hub_freebsd.go +++ b/transport/internet/udp/hub_freebsd.go @@ -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)