From d7cdc878ff5e62ba307417e07a0f8994a016609f Mon Sep 17 00:00:00 2001 From: gVisor bot Date: Fri, 16 Aug 2019 21:38:27 +0800 Subject: [PATCH] Fix: socks address stringify buffer overflow --- component/socks5/socks5.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/component/socks5/socks5.go b/component/socks5/socks5.go index b16c3b69..1dd60391 100644 --- a/component/socks5/socks5.go +++ b/component/socks5/socks5.go @@ -48,8 +48,9 @@ func (a Addr) String() string { switch a[0] { case AtypDomainName: - host = string(a[2 : 2+int(a[1])]) - port = strconv.Itoa((int(a[2+int(a[1])]) << 8) | int(a[2+int(a[1])+1])) + hostLen := uint16(a[1]) + host = string(a[2 : 2+hostLen]) + port = strconv.Itoa((int(a[2+hostLen]) << 8) | int(a[2+hostLen+1])) case AtypIPv4: host = net.IP(a[1 : 1+net.IPv4len]).String() port = strconv.Itoa((int(a[1+net.IPv4len]) << 8) | int(a[1+net.IPv4len+1]))