Skip to content

Commit 500d3c8

Browse files
committed
Fix bug generating TLS cert when listen hostname is empty
1 parent f6a462e commit 500d3c8

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

internal/tls/ca.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -102,20 +102,26 @@ func hostsToIPAndDNS(hosts []string) ([]net.IP, []string) {
102102
ips := []net.IP{}
103103
dnsNames := []string{}
104104
for _, host := range hosts {
105+
if host == "" {
106+
continue
107+
}
105108
host := host
106109
ip := net.ParseIP(host)
107110
if ip != nil {
108111
ips = append(ips, ip)
109112
} else {
110113
dnsNames = append(dnsNames, host)
111-
112114
for _, network := range []string{"ip4", "ip6"} {
113115
addr, err := net.ResolveIPAddr(network, host)
114-
if err == nil {
115-
ips = append(ips, addr.IP)
116-
} else {
116+
if err != nil {
117117
log.Logf(10, "failed to resolve %s: %s", host, err)
118+
continue
119+
}
120+
if addr == nil || addr.IP == nil {
121+
log.Logf(10, "failed to resolve %s: nil address returned", host)
122+
continue
118123
}
124+
ips = append(ips, addr.IP)
119125
}
120126
}
121127
}

0 commit comments

Comments
 (0)