From 2e5e1657194d41102f42ad4e71bb42ac0ae1e5d4 Mon Sep 17 00:00:00 2001 From: Aaron Paterson Date: Thu, 20 Nov 2025 14:30:22 -0700 Subject: [PATCH] check addr and netw first --- caddyconfig/httpcaddyfile/addresses.go | 32 ++++++++++++-------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/caddyconfig/httpcaddyfile/addresses.go b/caddyconfig/httpcaddyfile/addresses.go index 244c9f7da..997405ba6 100644 --- a/caddyconfig/httpcaddyfile/addresses.go +++ b/caddyconfig/httpcaddyfile/addresses.go @@ -357,37 +357,35 @@ func (st *ServerType) listenersForServerBlockAddress(sblock serverBlock, addr Ad lnIfaceAddresses := []string{} for _, ifaceAddress := range ifaceAddresses { - var ( - ip net.IP - ipok bool - ) + var addrok, netwok bool + + var ip net.IP switch ifaceAddressValue := ifaceAddress.(type) { case *net.IPAddr: - ip, ipok = ifaceAddressValue.IP, true + ip, addrok = ifaceAddressValue.IP, true + netwok = len(ip) == net.IPv4len && caddy.IsIPv4Network(lnNetw) || len(ip) == net.IPv6len && caddy.IsIPv6Network(lnNetw) case *net.IPNet: - ip, ipok = ifaceAddressValue.IP, true + ip, addrok = ifaceAddressValue.IP, true + netwok = len(ip) == net.IPv4len && caddy.IsIPv4Network(lnNetw) || len(ip) == net.IPv6len && caddy.IsIPv6Network(lnNetw) case *net.TCPAddr: - ip, ipok = ifaceAddressValue.IP, true + ip, addrok, netwok = ifaceAddressValue.IP, true, caddy.IsTCPNetwork(lnNetw) case *net.UDPAddr: - ip, ipok = ifaceAddressValue.IP, true + ip, addrok, netwok = ifaceAddressValue.IP, true, caddy.IsUDPNetwork(lnNetw) } - if ipok { - if len(ip) == net.IPv4len && caddy.IsIPv4Network(lnNetw) || len(ip) == net.IPv6len && caddy.IsIPv6Network(lnNetw) { + if addrok { + if netwok { lnIfaceAddresses = append(lnIfaceAddresses, ip.String()) } continue } - var ( - name string - nameok bool - ) + var name string switch ifaceAddressValue := ifaceAddress.(type) { case *net.UnixAddr: - name, nameok = ifaceAddressValue.Name, true + name, addrok, netwok = ifaceAddressValue.Name, true, caddy.IsUnixNetwork(lnNetw) } - if nameok { - if caddy.IsUnixNetwork(lnNetw) { + if addrok { + if netwok { lnIfaceAddresses = append(lnIfaceAddresses, name) } continue