Commit c2a8169a authored by Giampaolo Rodola's avatar Giampaolo Rodola

Fix issue #16646: ftplib.FTP.makeport() might lose socket error details. ...

Fix issue #16646: ftplib.FTP.makeport() might lose socket error details.  (patch by Serhiy Storchaka)
parent 78efadb8
...@@ -273,21 +273,24 @@ class FTP: ...@@ -273,21 +273,24 @@ class FTP:
def makeport(self): def makeport(self):
'''Create a new socket and send a PORT command for it.''' '''Create a new socket and send a PORT command for it.'''
msg = "getaddrinfo returns an empty list" err = None
sock = None sock = None
for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE): for res in socket.getaddrinfo(None, 0, self.af, socket.SOCK_STREAM, 0, socket.AI_PASSIVE):
af, socktype, proto, canonname, sa = res af, socktype, proto, canonname, sa = res
try: try:
sock = socket.socket(af, socktype, proto) sock = socket.socket(af, socktype, proto)
sock.bind(sa) sock.bind(sa)
except socket.error, msg: except socket.error, err:
if sock: if sock:
sock.close() sock.close()
sock = None sock = None
continue continue
break break
if not sock: if sock is None:
raise socket.error, msg if err is not None:
raise err
else:
raise socket.error("getaddrinfo returns an empty list")
sock.listen(1) sock.listen(1)
port = sock.getsockname()[1] # Get proper port port = sock.getsockname()[1] # Get proper port
host = self.sock.getsockname()[0] # Get proper host host = self.sock.getsockname()[0] # Get proper host
......
...@@ -160,6 +160,9 @@ Core and Builtins ...@@ -160,6 +160,9 @@ Core and Builtins
Library Library
------- -------
- Issue #16646: ftplib.FTP.makeport() might lose socket error details.
(patch by Serhiy Storchaka)
- Issue #16626: Fix infinite recursion in glob.glob() on Windows when the - Issue #16626: Fix infinite recursion in glob.glob() on Windows when the
pattern contains a wildcard in the drive or UNC path. Patch by Serhiy pattern contains a wildcard in the drive or UNC path. Patch by Serhiy
Storchaka. Storchaka.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment