Переглянути джерело

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 роки тому
джерело
коміт
9a9a85cd55
1 змінених файлів з 10 додано та 7 видалено
  1. 10
    7
      irc/net.go

+ 10
- 7
irc/net.go Переглянути файл

@@ -28,16 +28,19 @@ func AddrLookupHostname(addr net.Addr) string {
28 28
 // LookupHostname returns the hostname for `addr` if it has one. Otherwise, just returns `addr`.
29 29
 func LookupHostname(addr string) string {
30 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 46
 var allowedHostnameChars = "abcdefghijklmnopqrstuvwxyz1234567890-."

Завантаження…
Відмінити
Зберегти