jwhited / wgsd

A CoreDNS plugin that provides WireGuard peer information via DNS-SD semantics
https://www.jordanwhited.com/posts/wireguard-endpoint-discovery-nat-traversal/
MIT License
818 stars 76 forks source link

Server panic when using wgsd-client #26

Closed traysh closed 3 years ago

traysh commented 3 years ago

Corefile:

.:5353 {
        debug
        wgsd japuba.net.br wg0 {
            self
        }
}

Server output:

./coredns
.:5353
CoreDNS-1.8.0
linux/arm, go1.15.6, 
[DEBUG] plugin/wgsd: received query for: mql7ok6ufp76w6t3xf22vvkygx4x22gdka4ayhn76poqtkplxm3q====._wireguard._udp. type: SRV
panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x119c0e4]

goroutine 58 [running]:
github.com/jwhited/wgsd.getHostRR(0x420c960, 0x57, 0x0, 0x1, 0x458e101)
        /home/alarm/downloads/wgsd/wgsd.go:232 +0x14
github.com/jwhited/wgsd.handleSRV(0x422f5e0, 0x1739fa8, 0x411ff50, 0x412ac10, 0xe, 0x0, 0x420c960, 0x57, 0x0, 0x0, ...)
        /home/alarm/downloads/wgsd/wgsd.go:106 +0x198
github.com/jwhited/wgsd.(*WGSD).ServeDNS(0x44c6760, 0x1733540, 0x42ea360, 0x1739fa8, 0x411ff50, 0x422f5e0, 0x1b710, 0x411ff40, 0x10)
        /home/alarm/downloads/wgsd/wgsd.go:227 +0x2c8
github.com/coredns/coredns/core/dnsserver.(*Server).ServeDNS(0x44cb080, 0x1733540, 0x42ea360, 0x1739fa8, 0x411ff50, 0x422f5e0)
        /home/alarm/go/pkg/mod/github.com/coredns/coredns@v1.8.0/core/dnsserver/server.go:289 +0x3b4
github.com/coredns/coredns/core/dnsserver.(*Server).ServePacket.func1(0x173ae18, 0x4480960, 0x422f5e0)
        /home/alarm/go/pkg/mod/github.com/coredns/coredns@v1.8.0/core/dnsserver/server.go:126 +0x80
github.com/miekg/dns.HandlerFunc.ServeDNS(0x41ea030, 0x173ae18, 0x4480960, 0x422f5e0)
        /home/alarm/go/pkg/mod/github.com/miekg/dns@v1.1.34/server.go:37 +0x34
github.com/miekg/dns.(*Server).serveDNS(0x41f20a0, 0x40e4200, 0x68, 0x200, 0x4480960)
        /home/alarm/go/pkg/mod/github.com/miekg/dns@v1.1.34/server.go:617 +0x298
github.com/miekg/dns.(*Server).serveUDPPacket(0x41f20a0, 0x41e8060, 0x40e4200, 0x68, 0x200, 0x44c8368, 0x411ff10)
        /home/alarm/go/pkg/mod/github.com/miekg/dns@v1.1.34/server.go:557 +0x98
created by github.com/miekg/dns.(*Server).serveUDP
        /home/alarm/go/pkg/mod/github.com/miekg/dns@v1.1.34/server.go:487 +0x1fc

Client output:

./wgsd-client -device wg0 -dns 10.34.33.2:5353 -zone japuba.net.br
2021/01/06 22:52:28 [ZBf3K9Qr/+t6e7l1qtVYNfl9aMNQOAwdv/PdCanruzc=] failed to lookup SRV: read udp 10.34.33.10:45163->10.34.33.2:5353: i/o timeout
2021/01/06 22:52:28 [RP2teEPOF6La6jkqUGt/zXeiYRLdwYnbNNdqV7898RE=] failed to lookup SRV: read udp 10.34.33.10:41977->10.34.33.2:5353: read: connection refused
2021/01/06 22:52:29 [h4E4dbJoTSwfQGtudK+qmSUjd0hhR3zPTYs8tDbW21Q=] failed to lookup SRV: read udp 10.34.33.10:47761->10.34.33.2:5353: read: connection refused
2021/01/06 22:52:29 [OxmA/ZUQlTWrRSV+2QLyPb9AS6YkeB3ZSYGLcH8zBl4=] failed to lookup SRV: read udp 10.34.33.10:55267->10.34.33.2:5353: read: connection refused
2021/01/06 22:52:29 [EYu9sqfU/7ebk/dYWQ4y4UxYve/PGPwNSdOipVpIqEY=] failed to lookup SRV: read udp 10.34.33.10:46015->10.34.33.2:5353: read: connection refused
jwhited commented 3 years ago

thanks for the report, fix is in https://github.com/jwhited/wgsd/commit/7eaacc000ba331634a8023ce0d08521267020f99