Skip to content

Commit

Permalink
fix(udp): check addr nil (close 1807)
Browse files Browse the repository at this point in the history
  • Loading branch information
ksco.he authored and yuhan6665 committed Aug 13, 2022
1 parent b673147 commit 76638d7
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion transport/internet/udp/hub_freebsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand All @@ -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)
Expand Down

0 comments on commit 76638d7

Please sign in to comment.