From 01be46f62051d02cb6a36c9b47b37b24e5758c81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?P=C3=A9ter=20Szil=C3=A1gyi?= Date: Thu, 15 Dec 2016 15:43:59 +0200 Subject: [PATCH] crypto/ssh: use net.IP.Equal instead of bytes.Equal A net.IP may be represented by both by a 4 as well as a 16 byte long byte slice. Because of this, it is not safe to compare IP addresses using bytes.Equal as the same IP address using a different internal representation will produce mismatches. Change-Id: I0d228771cf363ccfb9532f8bc2a2fc8eff61f6e9 Reviewed-on: https://go-review.googlesource.com/34450 Reviewed-by: Brad Fitzpatrick Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- ssh/server.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ssh/server.go b/ssh/server.go index 37df1b3..9037470 100644 --- a/ssh/server.go +++ b/ssh/server.go @@ -242,7 +242,7 @@ func checkSourceAddress(addr net.Addr, sourceAddr string) error { } if allowedIP := net.ParseIP(sourceAddr); allowedIP != nil { - if bytes.Equal(allowedIP, tcpAddr.IP) { + if allowedIP.Equal(tcpAddr.IP) { return nil } } else {