mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
Merged revisions 84289 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/branches/py3k ........ r84289 | giampaolo.rodola | 2010-08-24 00:28:13 +0200 (mar, 24 ago 2010) | 1 line fix issue 9129: adds proper error handling on accept() when smtpd accepts new incoming connections. ........
This commit is contained in:
parent
3fac43f89f
commit
ed2ce469f3
2 changed files with 26 additions and 2 deletions
25
Lib/smtpd.py
25
Lib/smtpd.py
|
@ -121,7 +121,15 @@ class SMTPChannel(asynchat.async_chat):
|
||||||
self.__rcpttos = []
|
self.__rcpttos = []
|
||||||
self.__data = ''
|
self.__data = ''
|
||||||
self.__fqdn = socket.getfqdn()
|
self.__fqdn = socket.getfqdn()
|
||||||
self.__peer = conn.getpeername()
|
try:
|
||||||
|
self.__peer = conn.getpeername()
|
||||||
|
except socket.error as err:
|
||||||
|
# a race condition may occur if the other end is closing
|
||||||
|
# before we can get the peername
|
||||||
|
self.close()
|
||||||
|
if err.args[0] != errno.ENOTCONN:
|
||||||
|
raise
|
||||||
|
return
|
||||||
print('Peer:', repr(self.__peer), file=DEBUGSTREAM)
|
print('Peer:', repr(self.__peer), file=DEBUGSTREAM)
|
||||||
self.push('220 %s %s' % (self.__fqdn, __version__))
|
self.push('220 %s %s' % (self.__fqdn, __version__))
|
||||||
self.set_terminator(b'\r\n')
|
self.set_terminator(b'\r\n')
|
||||||
|
@ -289,7 +297,20 @@ class SMTPServer(asyncore.dispatcher):
|
||||||
localaddr, remoteaddr), file=DEBUGSTREAM)
|
localaddr, remoteaddr), file=DEBUGSTREAM)
|
||||||
|
|
||||||
def handle_accept(self):
|
def handle_accept(self):
|
||||||
conn, addr = self.accept()
|
try:
|
||||||
|
conn, addr = self.accept()
|
||||||
|
except TypeError:
|
||||||
|
# sometimes accept() might return None
|
||||||
|
return
|
||||||
|
except socket.error as err:
|
||||||
|
# ECONNABORTED might be thrown
|
||||||
|
if err.args[0] != errno.ECONNABORTED:
|
||||||
|
raise
|
||||||
|
return
|
||||||
|
else:
|
||||||
|
# sometimes addr == None instead of (ip, port)
|
||||||
|
if addr == None:
|
||||||
|
return
|
||||||
print('Incoming connection from %s' % repr(addr), file=DEBUGSTREAM)
|
print('Incoming connection from %s' % repr(addr), file=DEBUGSTREAM)
|
||||||
channel = SMTPChannel(self, conn, addr)
|
channel = SMTPChannel(self, conn, addr)
|
||||||
|
|
||||||
|
|
|
@ -95,6 +95,9 @@ C-API
|
||||||
Library
|
Library
|
||||||
-------
|
-------
|
||||||
|
|
||||||
|
- Issue #9129: smtpd.py is vulnerable to DoS attacks deriving from missing
|
||||||
|
error handling when accepting a new connection.
|
||||||
|
|
||||||
- Issue #658749: asyncore's connect() method now correctly interprets winsock
|
- Issue #658749: asyncore's connect() method now correctly interprets winsock
|
||||||
errors.
|
errors.
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue