[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [goptlib/master] Convert IP to IPv4 before writing it in SOCKS response.



commit 7cbdfa4c1514b9667101b9e7fb6c7682de157ff3
Author: David Fifield <david@xxxxxxxxxxxxxxx>
Date:   Sat Dec 7 21:26:15 2013 -0800

    Convert IP to IPv4 before writing it in SOCKS response.
    
    This was a bug; if the IP was a 16-byte slice, then we would read the
    first four bytes, which were zero. Document that address families other
    than IPv4 fill the four address bytes with zero, so that we sort of work
    with IPv6.
---
 socks.go |   15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)

diff --git a/socks.go b/socks.go
index a5889fa..8534636 100644
--- a/socks.go
+++ b/socks.go
@@ -161,17 +161,22 @@ func readSocks4aConnect(s io.Reader) (req SocksRequest, err error) {
 	return
 }
 
-// Send a SOCKS4a response with the given code and address.
+// Send a SOCKS4a response with the given code and address. If the IP field
+// inside addr is not an IPv4 address, the IP portion of the response will be
+// four zero bytes.
 func sendSocks4aResponse(w io.Writer, code byte, addr *net.TCPAddr) error {
 	var resp [8]byte
 	resp[0] = socksResponseVersion
 	resp[1] = code
 	resp[2] = byte((addr.Port >> 8) & 0xff)
 	resp[3] = byte((addr.Port >> 0) & 0xff)
-	resp[4] = addr.IP[0]
-	resp[5] = addr.IP[1]
-	resp[6] = addr.IP[2]
-	resp[7] = addr.IP[3]
+	ipv4 := addr.IP.To4()
+	if ipv4 != nil {
+		resp[4] = ipv4[0]
+		resp[5] = ipv4[1]
+		resp[6] = ipv4[2]
+		resp[7] = ipv4[3]
+	}
 	_, err := w.Write(resp[:])
 	return err
 }



_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits