UDP proxy bug in python version less than 3.7
yuchting opened this issue · 1 comments
yuchting commented
Here's a simple bug I met and I will give a reminder to resolve.
socket.type will be changed after settimeout/setblocking calling. And pysocks will not send proxy data after these 2 functions called, because socks.sockssocket.sendto just use socket.type to adjust how it will send message.
just look in python3.6.8:
Python 3.6.8 (default, Apr 2 2020, 13:34:55)
[GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>>> udp_socket.type
<SocketKind.SOCK_DGRAM: 2>
>>> udp_socket.setblocking(1)
>>> udp_socket.type
<SocketKind.SOCK_DGRAM: 2>
>>> udp_socket.setblocking(0)
>>> udp_socket.type
2050 <----------------- look, changed
>>>
in python3.8:
Python 3.8.3 (tags/v3.8.3:6f8c832, May 13 2020, 22:37:02) [MSC v.1924 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import socket
>>> udp_socket = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
>>> udp_socket.type
<SocketKind.SOCK_DGRAM: 2>
>>> udp_socket.setblocking(0)
>>> udp_socket.type
<SocketKind.SOCK_DGRAM: 2> <----------------- look, won't be changed
>>>
in python official document, they saied:
- Changed in version 3.7: The method no longer applies SOCK_NONBLOCK flag on socket.type.
so the following code of pysocks will has a small bug:
def sendto(self, bytes, *args, **kwargs):
if self.type != socket.SOCK_DGRAM: # <---------------- here
return super(socksocket, self).sendto(bytes, *args, **kwargs)
if not self._proxyconn:
self.bind(("", 0))
of course all code like this equal judgement for check whether is UDP socket might have same issue in python version less then 3.7, I hope you will fix it in next version.
please don't mind, just reminder, thanks for your project to help me.