Re: [gentoo-portage-dev] [PATCH] bin/socks5-server.py: convert address from bytes to str (bug 604474)

2017-01-12 Thread Zac Medico
On 01/12/2017 03:10 PM, Brian Dolbec wrote:
> On Thu, 12 Jan 2017 09:36:36 -0800
> Zac Medico  wrote:
> 
>> 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)
> 
> 
> looks good
> 

Thanks, pushed:

https://gitweb.gentoo.org/proj/portage.git/commit/?id=0d32c30b1db848e9eac6fe2e216e6373846467a2
-- 
Thanks,
Zac



Re: [gentoo-portage-dev] [PATCH] bin/socks5-server.py: convert address from bytes to str (bug 604474)

2017-01-12 Thread Brian Dolbec
On Thu, 12 Jan 2017 09:36:36 -0800
Zac Medico  wrote:

> 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)


looks good
-- 
Brian Dolbec 




[gentoo-portage-dev] [PATCH] bin/socks5-server.py: convert address from bytes to str (bug 604474)

2017-01-12 Thread Zac Medico
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