Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UDP proxy bug in python version less than 3.7 #143

Closed
yuchting opened this issue Jun 12, 2020 · 1 comment
Closed

UDP proxy bug in python version less than 3.7 #143

yuchting opened this issue Jun 12, 2020 · 1 comment

Comments

@yuchting
Copy link

yuchting commented Jun 12, 2020

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.

@yuchting
Copy link
Author

sorry, this RP has resolved this issue:
#128

I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant