From 5c8c9a2c330db5a96eb1149d388b411e7ec5acd3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Giampaolo=20Rodol=C3=A0?= Date: Sat, 21 Aug 2010 18:35:05 +0000 Subject: fix issue #9129: added proper error handling when accepting new connections in SMTPServer.handle_accept --- Lib/smtpd.py | 17 +++++++++++++++-- Misc/NEWS | 3 +++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/Lib/smtpd.py b/Lib/smtpd.py index b408278..e8459f0 100755 --- a/Lib/smtpd.py +++ b/Lib/smtpd.py @@ -413,8 +413,21 @@ class SMTPServer(asyncore.dispatcher): self.__class__.__name__, time.ctime(time.time()), localaddr, remoteaddr), file=DEBUGSTREAM) - def handle_accept(self): - conn, addr = self.accept() + def handle_accept(self) + try: + conn, addr = self.accept() + except TypeError: + # sometimes accept() might return None + return + except socket.error, err: + # ECONNABORTED might be thrown + if err[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) channel = self.channel_class(self, conn, addr) diff --git a/Misc/NEWS b/Misc/NEWS index 019cd4b..6552a79 100644 --- a/Misc/NEWS +++ b/Misc/NEWS @@ -117,6 +117,9 @@ Extensions Library ------- +- Issue #9129: smtpd.py module is vulnerable to DoS attacks due to missing + error handling when accepting new connections. + - Issue #843590: Make "macintosh" an alias to the "mac_roman" encoding. - Create os.fsdecode(): decode from the filesystem encoding with -- cgit v0.12