commit:     0d32c30b1db848e9eac6fe2e216e6373846467a2
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Jan  9 20:18:58 2017 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Thu Jan 12 23:32:17 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=0d32c30b

bin/socks5-server.py: convert address from bytes to str (bug 604474)

Use the idna codec to decode the destination address that is read
from the client. This fixes a "TypeError: must be str, not bytes"
exception raised from getaddrinfo with Python 3.4.5.

X-Gentoo-Bug: 604474
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=604474
Acked-by: Brian Dolbec <dolsen <AT> gentoo.org>

 bin/socks5-server.py | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/bin/socks5-server.py b/bin/socks5-server.py
index cfe3ece..d46cf53 100644
--- a/bin/socks5-server.py
+++ b/bin/socks5-server.py
@@ -83,6 +83,11 @@ class Socks5Server(object):
                                data = yield from reader.readexactly(1)
                                addr_len, = struct.unpack('!B', data)
                                addr = yield from reader.readexactly(addr_len)
+                               try:
+                                       addr = addr.decode('idna')
+                               except UnicodeDecodeError:
+                                       rpl = 0x04  # host unreachable
+
                        elif atyp == 0x04:  # IPv6
                                data = yield from reader.readexactly(16)
                                addr = socket.inet_ntop(socket.AF_INET6, data)

Reply via email to