From e61091d240ada4947269698b1ff3fca6fe4a7d53 Mon Sep 17 00:00:00 2001 From: Simon Frei Date: Thu, 5 Aug 2021 01:04:22 +0200 Subject: [PATCH] lib/stun: Prevent nil deref when naming service (#7872) --- lib/stun/stun.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/stun/stun.go b/lib/stun/stun.go index ee7b88783..4ac476319 100644 --- a/lib/stun/stun.go +++ b/lib/stun/stun.go @@ -107,8 +107,14 @@ func New(cfg config.Wrapper, subscriber Subscriber, conn *net.UDPConn) (*Service client.SetSoftwareName("") // Explicitly unset this, seems to freak some servers out. // Return the service and the other conn to the client + name := "Stun@" + if local := conn.LocalAddr(); local != nil { + name += local.Network() + "://" + local.String() + } else { + name += "unknown" + } s := &Service{ - name: "Stun@" + conn.LocalAddr().Network() + "://" + conn.LocalAddr().String(), + name: name, cfg: cfg, subscriber: subscriber,