From 6af96bfdb7677280795604bf3e86c81148c11d24 Mon Sep 17 00:00:00 2001 From: Josh Rickmar Date: Thu, 14 Jan 2016 12:43:42 -0500 Subject: [PATCH] Correctly handle RPC listen addresses with IPv6 zones. Fixes #341. --- rpcserver.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/rpcserver.go b/rpcserver.go index 3beae81..1b6f809 100644 --- a/rpcserver.go +++ b/rpcserver.go @@ -33,6 +33,7 @@ import ( "os" "path/filepath" "runtime" + "strings" "sync" "sync/atomic" "time" @@ -194,6 +195,16 @@ func parseListeners(addrs []string) ([]string, []string, error) { continue } + // Remove the IPv6 zone from the host, if present. The zone + // prevents ParseIP from correctly parsing the IP address. + // ResolveIPAddr is intentionally not used here due to the + // possibility of leaking a DNS query over Tor if the host is a + // hostname and not an IP address. + zoneIndex := strings.Index(host, "%") + if zoneIndex != -1 { + host = host[:zoneIndex] + } + // Parse the IP. ip := net.ParseIP(host) if ip == nil {