From df7c7eec4a39bd0eb73a66a4e9d38e70efae721e Mon Sep 17 00:00:00 2001 From: Nathan Brown Date: Mon, 26 Apr 2021 20:21:47 -0500 Subject: [PATCH] Get out faster on nil udpAddr (#449) --- outside.go | 2 +- remote_list.go | 4 ++++ udp_all.go | 12 ++++++++++++ 3 files changed, 17 insertions(+), 1 deletion(-) diff --git a/outside.go b/outside.go index 3fc2170..88cf6af 100644 --- a/outside.go +++ b/outside.go @@ -340,7 +340,7 @@ func (f *Interface) handleRecvError(addr *udpAddr, h *Header) { if !hostinfo.RecvErrorExceeded() { return } - if hostinfo.remote != nil && hostinfo.remote.String() != addr.String() { + if hostinfo.remote != nil && hostinfo.remote.Equals(addr) { f.l.Infoln("Someone spoofing recv_errors? ", addr, hostinfo.remote) return } diff --git a/remote_list.go b/remote_list.go index cf40ad8..e88a8b0 100644 --- a/remote_list.go +++ b/remote_list.go @@ -99,6 +99,10 @@ func (r *RemoteList) ForEach(preferredRanges []*net.IPNet, forEach forEachFunc) // CopyAddrs locks and makes a deep copy of the deduplicated address list // The deduplication work may need to occur here, so you must pass preferredRanges func (r *RemoteList) CopyAddrs(preferredRanges []*net.IPNet) []*udpAddr { + if r == nil { + return nil + } + r.Rebuild(preferredRanges) r.RLock() diff --git a/udp_all.go b/udp_all.go index 05883b9..1ce8135 100644 --- a/udp_all.go +++ b/udp_all.go @@ -33,14 +33,26 @@ func (ua *udpAddr) Equals(t *udpAddr) bool { } func (ua *udpAddr) String() string { + if ua == nil { + return "" + } + return net.JoinHostPort(ua.IP.String(), fmt.Sprintf("%v", ua.Port)) } func (ua *udpAddr) MarshalJSON() ([]byte, error) { + if ua == nil { + return nil, nil + } + return json.Marshal(m{"ip": ua.IP, "port": ua.Port}) } func (ua *udpAddr) Copy() *udpAddr { + if ua == nil { + return nil + } + nu := udpAddr{ Port: ua.Port, IP: make(net.IP, len(ua.IP)),