8000 Issue #16041: CVE-2013-1752: poplib: Limit maximum line lengths to 20… · python/cpython@eaca861 · GitHub
[go: up one dir, main page]

Skip to content

Commit eaca861

Browse files
committed
Issue #16041: CVE-2013-1752: poplib: Limit maximum line lengths to 2048 to
prevent readline() calls from consuming too much memory. Patch by Jyrki Pulliainen.
1 parent 210ee47 commit eaca861

File tree

3 files changed

+19
-2
lines changed

3 files changed

+19
-2
lines changed

Lib/poplib.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,12 @@ class error_proto(Exception): pass
3232
LF = b'\n'
3333
CRLF = CR+LF
3434

35+
# maximal line length when calling readline(). This is to prevent
36+
# reading arbitrary lenght lines. RFC 1939 limits POP3 line length to
37+
# 512 characters, including CRLF. We have selected 2048 just to be on
38+
# the safe side.
39+
_MAXLINE = 2048
40+
3541

3642
class POP3:
3743

@@ -107,7 +113,10 @@ def _putcmd(self, line):
107113
# Raise error_proto('-ERR EOF') if the connection is closed.
108114

109115
def _getline(self):
110-
line = self.file.readline()
116+
line = self.file.readline(_MAXLINE + 1)
117+
if len(line) > _MAXLINE:
118+
raise error_proto('line too long')
119+
111120
if self._debugging > 1: print('*get*', repr(line))
112121
if not line: raise error_proto('-ERR EOF')
113122
octets = len(line)

Lib/test/test_poplib.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ def cmd_stat(self, arg):
8383

8484
def cmd_list(self, arg):
8585
if arg:
86-
self.push('+OK %s %s' %(arg, arg))
86+
self.push('+OK %s %s' % (arg, arg))
8787
else:
8888
self.push('+OK')
8989
asynchat.async_chat.push(self, LIST_RESP)
@@ -204,6 +204,10 @@ def test_retr(self):
204204
foo = self.client.retr('foo')
205205
self.assertEqual(foo, expected)
206206

207+
def test_too_long_lines(self):
208+
self.assertRaises(poplib.error_proto, self.client._shortcmd,
209+
'echo +%s' % ((poplib._MAXLINE + 10) * 'a'))
210+
207211
def test_dele(self):
208212
self.assertOK(self.client.dele('foo'))
209213

Misc/NEWS

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@ What's New in Python 3.2.6?
1010
Library
1111
-------
1212

13+
- Issue #16041: CVE-2013-1752: poplib: Limit maximum line lengths to 2048 to
14+
prevent readline() calls from consuming too much memory. Patch by Jyrki
15+
Pulliainen.
16+
1317
- Issue #16042: CVE-2013-1752: smtplib: Limit amount of data read by
1418
limiting the call to readline(). Original patch by Christian Heimes.
1519

0 commit comments

Comments
 (0)
0