dougbw / coredns_omada

CoreDNS plugin for TP-Link Omada SDN
Apache License 2.0
90 stars 9 forks source link

updateZones() panic: runtime error: invalid memory address or nil pointer dereference #13

Closed rfranky closed 1 year ago

rfranky commented 1 year ago

Getting panic error while updating zones.

Maybe a null ip on a client on omada... We have a few of those

`[INFO] plugin/omada: logging in... [INFO] plugin/omada: found '1' sites: [MySite] [INFO] plugin/omada: update: updating zones... panic: runtime error: invalid memory address or nil pointer dereference [signal SIGSEGV: segmentation violation code=0x1 addr=0x0 pc=0x563220]

goroutine 1 [running]: net.networkNumberAndMask(0xc000bf64f0?) /usr/local/go/src/net/ip.go:498 net.(IPNet).Contains(0xc000bf64f0?, {0xc0008e6930, 0x10, 0x19?}) /usr/local/go/src/net/ip.go:522 +0x27 github.com/dougbw/coredns_omada.(Omada).updateZones(0xc0002fe480, {0x1?, 0x21d806a?}) /coredns_omada/update.go:141 +0x12c6 github.com/dougbw/coredns_omada.setup(0xc000052990) /coredns_omada/setup.go:52 +0x6cb github.com/coredns/caddy.executeDirectives(0xc00032c400, {0x7fff5f1eaecc, 0x15}, {0x3749d40, 0x35, 0x203000?}, {0xc00031bd00, 0x1, 0x8?}, 0x0) /go/pkg/mod/github.com/coredns/caddy@v1.1.1/caddy.go:661 +0x5dd github.com/coredns/caddy.ValidateAndExecuteDirectives({0x26becb8?, 0xc00070cb80}, 0x8?, 0x0) /go/pkg/mod/github.com/coredns/caddy@v1.1.1/caddy.go:612 +0x3ec github.com/coredns/caddy.startWithListenerFds({0x26becb8, 0xc00070cb80}, 0xc00032c400, 0x0) /go/pkg/mod/github.com/coredns/caddy@v1.1.1/caddy.go:515 +0x272 github.com/coredns/caddy.Start({0x26becb8, 0xc00070cb80}) /go/pkg/mod/github.com/coredns/caddy@v1.1.1/caddy.go:472 +0xe5 github.com/coredns/coredns/coremain.Run() /coredns/coremain/run.go:66 +0x1cd main.main() /coredns/coredns.go:12 +0x17`

dougbw commented 1 year ago

It looks like the code is failing when checking to see if a particular client IP address exists within a subnet range. I am guessing this is caused by a client having an IPv6 address as I can see the code would not handle this scenario (and it was never tested with IPv6 at all). I will do some investigation and see if I can reproduce/resolve the issue.

rfranky commented 1 year ago

Let me know if you need access to my controller to debug.

dougbw commented 1 year ago

I have just pushed a release which I think will address the issue by skipping over clients with null IPv4 addresses - The original code would crash when attempting to parse the null address - https://github.com/dougbw/coredns_omada/releases/tag/1.4.1

Keep in mind that this plugin does not support IPv6 DNS, I can't confirm whether IPv6 is the reason for your controller returning null IP addresses as I have not configured my network for IPv6 so have no means to validate this.