diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-09 15:33:57 +0200 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2019-05-09 15:42:35 +0200 |
commit | 586112b5d78abc99c9858c9a9a40756d5854d311 (patch) | |
tree | b1db0392cf492e0ffc72bdfe0dae818344d3772f | |
parent | dcb8f1aa6b14e538b76146d89f834b0ca98240af (diff) |
conn: remove scope when sanity checking IP address format
-rw-r--r-- | device/conn.go | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/device/conn.go b/device/conn.go index 3c2aa04..d57aa8c 100644 --- a/device/conn.go +++ b/device/conn.go @@ -10,6 +10,7 @@ import ( "golang.org/x/net/ipv4" "golang.org/x/net/ipv6" "net" + "strings" ) const ( @@ -41,13 +42,18 @@ type Endpoint interface { } func parseEndpoint(s string) (*net.UDPAddr, error) { - // ensure that the host is an IP address host, _, err := net.SplitHostPort(s) if err != nil { return nil, err } + if i := strings.LastIndexByte(host, '%'); i > 0 && strings.IndexByte(host, ':') >= 0 { + // Remove the scope, if any. ResolveUDPAddr below will use it, but here we're just + // trying to make sure with a small sanity test that this is a real IP address and + // not something that's likely to incur DNS lookups. + host = host[:i] + } if ip := net.ParseIP(host); ip == nil { return nil, errors.New("Failed to parse IP address: " + host) } |