mirror of
https://github.com/coredns/coredns.git
synced 2025-10-27 08:14:18 -04:00
fix(plugin): prevent panic when ListenHosts is empty (#7565)
This commit is contained in:
@@ -31,7 +31,10 @@ func setup(c *caddy.Controller) error {
|
|||||||
go func() {
|
go func() {
|
||||||
deadline := time.Now().Add(30 * time.Second)
|
deadline := time.Now().Add(30 * time.Second)
|
||||||
conf := dnsserver.GetConfig(c)
|
conf := dnsserver.GetConfig(c)
|
||||||
lh := conf.ListenHosts[0]
|
lh := ""
|
||||||
|
if len(conf.ListenHosts) > 0 {
|
||||||
|
lh = conf.ListenHosts[0]
|
||||||
|
}
|
||||||
addr := net.JoinHostPort(lh, conf.Port)
|
addr := net.JoinHostPort(lh, conf.Port)
|
||||||
|
|
||||||
for time.Now().Before(deadline) {
|
for time.Now().Before(deadline) {
|
||||||
|
|||||||
@@ -37,7 +37,7 @@ func traceParse(c *caddy.Controller) (*trace, error) {
|
|||||||
)
|
)
|
||||||
|
|
||||||
cfg := dnsserver.GetConfig(c)
|
cfg := dnsserver.GetConfig(c)
|
||||||
if cfg.ListenHosts[0] != "" {
|
if len(cfg.ListenHosts) > 0 && cfg.ListenHosts[0] != "" {
|
||||||
tr.serviceEndpoint = cfg.ListenHosts[0] + ":" + cfg.Port
|
tr.serviceEndpoint = cfg.ListenHosts[0] + ":" + cfg.Port
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
24
test/bind_test.go
Normal file
24
test/bind_test.go
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
package test
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestBind_FilterAll(t *testing.T) {
|
||||||
|
t.Parallel()
|
||||||
|
corefile := `.:0 {
|
||||||
|
bind 127.0.0.1 {
|
||||||
|
except 127.0.0.1
|
||||||
|
}
|
||||||
|
trace
|
||||||
|
loop
|
||||||
|
whoami
|
||||||
|
}`
|
||||||
|
inst, err := CoreDNSServer(corefile)
|
||||||
|
if inst != nil {
|
||||||
|
CoreDNSServerStop(inst)
|
||||||
|
}
|
||||||
|
if err == nil {
|
||||||
|
t.Log("server started; stopping immediately")
|
||||||
|
} else {
|
||||||
|
t.Logf("server failed to start as expected without listeners: %v", err)
|
||||||
|
}
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user