From 53e16d36dcf270c6bbd8ad9e31eb107e6c15f537 Mon Sep 17 00:00:00 2001 From: Zac Medico Date: Mon, 9 Jan 2017 12:18:58 -0800 Subject: [PATCH] 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 --- 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) -- 2.7.4