From 7a3b91390b6c26dc2a5258599827fbdc527d853c Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 24 Feb 2020 08:47:20 -0800 Subject: [PATCH] wgengine/magicsock: fix crash in Send when Endpoint isn't an AddrSet Signed-off-by: Brad Fitzpatrick --- wgengine/magicsock/magicsock.go | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/wgengine/magicsock/magicsock.go b/wgengine/magicsock/magicsock.go index c6643a0f2..23b7b785e 100644 --- a/wgengine/magicsock/magicsock.go +++ b/wgengine/magicsock/magicsock.go @@ -417,7 +417,16 @@ func appendDests(dsts []*net.UDPAddr, as *AddrSet, b []byte) (_ []*net.UDPAddr, var errNoDestinations = errors.New("magicsock: no destinations") func (c *Conn) Send(b []byte, ep conn.Endpoint) error { - as := ep.(*AddrSet) + var as *AddrSet + switch v := ep.(type) { + default: + panic(fmt.Sprintf("unexpected Endpoint type %T", v)) + case *singleEndpoint: + _, err := c.pconn.WriteTo(b, (*net.UDPAddr)(v)) + return err + case *AddrSet: + as = v + } var addrBuf [8]*net.UDPAddr dsts, roamAddr := appendDests(addrBuf[:0], as, b)