Browse Source

fix hostmask issue

PTR records ending in . (e.g., `google-public-dns-b.google.com.`)
were considered invalid
tags/v0.9.0
Shivaram Lingamneni 6 years ago
parent
commit
9a9a85cd55
1 changed files with 10 additions and 7 deletions
  1. 10
    7
      irc/net.go

+ 10
- 7
irc/net.go View File

28
 // LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
28
 // LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
29
 func LookupHostname(addr string) string {
29
 func LookupHostname(addr string) string {
30
 	names, err := net.LookupAddr(addr)
30
 	names, err := net.LookupAddr(addr)
31
-	if err != nil || len(names) < 1 || !IsHostname(names[0]) {
32
-		// return original address if no hostname found
33
-		if len(addr) > 0 && addr[0] == ':' {
34
-			// fix for IPv6 hostnames (so they don't start with a colon), same as all other IRCds
35
-			addr = "0" + addr
31
+	if err == nil && len(names) > 0 {
32
+		candidate := strings.TrimSuffix(names[0], ".")
33
+		if IsHostname(candidate) {
34
+			return candidate
36
 		}
35
 		}
37
-		return addr
38
 	}
36
 	}
39
 
37
 
40
-	return names[0]
38
+	// return original address if no hostname found
39
+	if len(addr) > 0 && addr[0] == ':' {
40
+		// fix for IPv6 hostnames (so they don't start with a colon), same as all other IRCds
41
+		addr = "0" + addr
42
+	}
43
+	return addr
41
 }
44
 }
42
 
45
 
43
 var allowedHostnameChars = "abcdefghijklmnopqrstuvwxyz1234567890-."
46
 var allowedHostnameChars = "abcdefghijklmnopqrstuvwxyz1234567890-."

Loading…
Cancel
Save