From 9a9a85cd55b87a315373ebf7e9cfd385cfd799fb Mon Sep 17 00:00:00 2001 From: Shivaram Lingamneni Date: Tue, 5 Sep 2017 11:43:50 -0400 Subject: [PATCH] fix hostmask issue PTR records ending in . (e.g., `google-public-dns-b.google.com.`) were considered invalid --- irc/net.go | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/irc/net.go b/irc/net.go index ba2e68a9..6ead2471 100644 --- a/irc/net.go +++ b/irc/net.go @@ -28,16 +28,19 @@ func AddrLookupHostname(addr net.Addr) string { // LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`. func LookupHostname(addr string) string { names, err := net.LookupAddr(addr) - if err != nil || len(names) < 1 || !IsHostname(names[0]) { - // return original address if no hostname found - if len(addr) > 0 && addr[0] == ':' { - // fix for IPv6 hostnames (so they don't start with a colon), same as all other IRCds - addr = "0" + addr + if err == nil && len(names) > 0 { + candidate := strings.TrimSuffix(names[0], ".") + if IsHostname(candidate) { + return candidate } - return addr } - return names[0] + // return original address if no hostname found + if len(addr) > 0 && addr[0] == ':' { + // fix for IPv6 hostnames (so they don't start with a colon), same as all other IRCds + addr = "0" + addr + } + return addr } var allowedHostnameChars = "abcdefghijklmnopqrstuvwxyz1234567890-."