소스 검색

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-."

Loading…
취소
저장