WeiEast / socksipy-branch

Automatically exported from code.google.com/p/socksipy-branch
0 stars 0 forks source link

Possible infinite loop in _negotiatehttp #7

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
In _negotiatehttp, the following loop may run indefinetly:

# We read the response until we get the string "\r\n\r\n"
resp = self.recv(1)
while resp.find("\r\n\r\n".encode()) == -1:
    resp = resp + self.recv(1)

If the server doesn't send the expected data or the connection breaks, this 
loop will never end. A possible solution may be the following:

# We read the response until we get the string "\r\n\r\n"
resp = self.recv(1)
if not resp:
    raise GeneralProxyError((0, "connection closed unexpectedly"))
while resp.find("\r\n\r\n".encode()) == -1:
    chunk = self.recv(1)
    if not chunk:
        raise GeneralProxyError((0, "connection closed unexpectedly"))
    resp = resp + chunk

Original issue reported on code.google.com by thomas.k...@gmail.com on 11 Nov 2011 at 11:35

GoogleCodeExporter commented 8 years ago
Ran into this.
my fix(for my particular case):
if resp != '':
            while resp.find("\r\n\r\n".encode()) == -1:
                resp = resp + self.recv(1)
        else:
            raise ProxyError #this can be any of the exceptions

Original comment by a.dasche...@gmail.com on 13 Jan 2012 at 5:11