summaryrefslogtreecommitdiffstats
path: root/Lib/smtplib.py
diff options
context:
space:
mode:
authorGeorg Brandl <georg@python.org>2014-01-25 08:02:18 (GMT)
committerGeorg Brandl <georg@python.org>2014-01-25 08:02:18 (GMT)
commitc11435399e7af8317e5a51642ee665347da2b97f (patch)
tree45a63ff03df5fda7b9e3c697331165ea5b22bbc0 /Lib/smtplib.py
parentf580d5b6f7468abf768a2ee6360168ad92893457 (diff)
downloadcpython-c11435399e7af8317e5a51642ee665347da2b97f.zip
cpython-c11435399e7af8317e5a51642ee665347da2b97f.tar.gz
cpython-c11435399e7af8317e5a51642ee665347da2b97f.tar.bz2
#16042: CVE-2013-1752: smtplib fix for unlimited readline() from socket
Diffstat (limited to 'Lib/smtplib.py')
-rwxr-xr-xLib/smtplib.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/smtplib.py b/Lib/smtplib.py
index 072b973..57f181b 100755
--- a/Lib/smtplib.py
+++ b/Lib/smtplib.py
@@ -62,6 +62,7 @@ SMTP_PORT = 25
SMTP_SSL_PORT = 465
CRLF = "\r\n"
bCRLF = b"\r\n"
+_MAXLINE = 8192 # more than 8 times larger than RFC 821, 4.5.3
OLDSTYLE_AUTH = re.compile(r"auth=(.*)", re.I)
@@ -364,7 +365,7 @@ class SMTP:
self.file = self.sock.makefile('rb')
while 1:
try:
- line = self.file.readline()
+ line = self.file.readline(_MAXLINE + 1)
except socket.error as e:
self.close()
raise SMTPServerDisconnected("Connection unexpectedly closed: "
@@ -374,6 +375,8 @@ class SMTP:
raise SMTPServerDisconnected("Connection unexpectedly closed")
if self.debuglevel > 0:
print('reply:', repr(line), file=stderr)
+ if len(line) > _MAXLINE:
+ raise SMTPResponseException(500, "Line too long.")
resp.append(line[4:].strip(b' \t\r\n'))
code = line[:3]
# Check that the error code is syntactically correct.