1 |
Use the idna codec to decode the destination address that is read |
2 |
from the client. This fixes a "TypeError: must be str, not bytes" |
3 |
exception raised from getaddrinfo with Python 3.4.5. |
4 |
|
5 |
X-Gentoo-Bug: 604474 |
6 |
X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=604474 |
7 |
--- |
8 |
bin/socks5-server.py | 5 +++++ |
9 |
1 file changed, 5 insertions(+) |
10 |
|
11 |
diff --git a/bin/socks5-server.py b/bin/socks5-server.py |
12 |
index cfe3ece..d46cf53 100644 |
13 |
--- a/bin/socks5-server.py |
14 |
+++ b/bin/socks5-server.py |
15 |
@@ -83,6 +83,11 @@ class Socks5Server(object): |
16 |
data = yield from reader.readexactly(1) |
17 |
addr_len, = struct.unpack('!B', data) |
18 |
addr = yield from reader.readexactly(addr_len) |
19 |
+ try: |
20 |
+ addr = addr.decode('idna') |
21 |
+ except UnicodeDecodeError: |
22 |
+ rpl = 0x04 # host unreachable |
23 |
+ |
24 |
elif atyp == 0x04: # IPv6 |
25 |
data = yield from reader.readexactly(16) |
26 |
addr = socket.inet_ntop(socket.AF_INET6, data) |
27 |
-- |
28 |
2.7.4 |