Gentoo Archives: gentoo-portage-dev

From: Brian Dolbec <dolsen@g.o>
To: gentoo-portage-dev@l.g.o
Subject: Re: [gentoo-portage-dev] [PATCH] bin/socks5-server.py: convert address from bytes to str (bug 604474)
Date: Thu, 12 Jan 2017 23:10:22
Message-Id: 20170112151017.0f198422.dolsen@gentoo.org
In Reply to: [gentoo-portage-dev] [PATCH] bin/socks5-server.py: convert address from bytes to str (bug 604474) by Zac Medico
1 On Thu, 12 Jan 2017 09:36:36 -0800
2 Zac Medico <zmedico@g.o> wrote:
3
4 > Use the idna codec to decode the destination address that is read
5 > from the client. This fixes a "TypeError: must be str, not bytes"
6 > exception raised from getaddrinfo with Python 3.4.5.
7 >
8 > X-Gentoo-Bug: 604474
9 > X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=604474
10 > ---
11 > bin/socks5-server.py | 5 +++++
12 > 1 file changed, 5 insertions(+)
13 >
14 > diff --git a/bin/socks5-server.py b/bin/socks5-server.py
15 > index cfe3ece..d46cf53 100644
16 > --- a/bin/socks5-server.py
17 > +++ b/bin/socks5-server.py
18 > @@ -83,6 +83,11 @@ class Socks5Server(object):
19 > data = yield from
20 > reader.readexactly(1) addr_len, = struct.unpack('!B', data)
21 > addr = yield from
22 > reader.readexactly(addr_len)
23 > + try:
24 > + addr = addr.decode('idna')
25 > + except UnicodeDecodeError:
26 > + rpl = 0x04 # host
27 > unreachable +
28 > elif atyp == 0x04: # IPv6
29 > data = yield from
30 > reader.readexactly(16) addr = socket.inet_ntop(socket.AF_INET6, data)
31
32
33 looks good
34 --
35 Brian Dolbec <dolsen>

Replies