From 0923f3c787a14e11fd3d8113763dcfd29c4c4b98 Mon Sep 17 00:00:00 2001 From: Robert Blenkinsopp Date: Mon, 16 May 2022 09:21:32 +0100 Subject: [PATCH] Check for nil interfaces on various functions This fixes #34 by ensuring that nil interfaces don't cause panics if supplied. --- dns.go | 8 ++++++++ service.go | 4 ++++ 2 files changed, 12 insertions(+) diff --git a/dns.go b/dns.go index 4bd04aa..03009f1 100644 --- a/dns.go +++ b/dns.go @@ -113,6 +113,10 @@ func NSEC(rr dns.RR, srv Service, iface *net.Interface) *dns.NSEC { } func A(srv Service, iface *net.Interface) []*dns.A { + if iface == nil { + return []*dns.A{} + } + ips := srv.IPsAtInterface(iface) var as []*dns.A @@ -135,6 +139,10 @@ func A(srv Service, iface *net.Interface) []*dns.A { } func AAAA(srv Service, iface *net.Interface) []*dns.AAAA { + if iface == nil { + return []*dns.AAAA{} + } + ips := srv.IPsAtInterface(iface) var aaaas []*dns.AAAA diff --git a/service.go b/service.go index b4fcc96..7f0b88e 100644 --- a/service.go +++ b/service.go @@ -147,6 +147,10 @@ func (s *Service) Interfaces() []*net.Interface { // IPsAtInterface returns the ip address at a specific interface. func (s *Service) IPsAtInterface(iface *net.Interface) []net.IP { + if iface == nil { + return []net.IP{} + } + if ips, ok := s.ifaceIPs[iface.Name]; ok { return ips }