summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChanho Park <chanho61.park@samsung.com>2014-08-19 19:47:58 +0900
committerChanho Park <chanho61.park@samsung.com>2014-08-19 19:47:58 +0900
commit106fdbbcad896511be508e1ca1a64e080717c718 (patch)
treeaefdf890a84d4b545ea8b7c02d7c7e0977662414
parentf3a523163d7535d8a90d0dacfebf104086c80b38 (diff)
downloadpython-106fdbbcad896511be508e1ca1a64e080717c718.tar.gz
python-106fdbbcad896511be508e1ca1a64e080717c718.tar.bz2
python-106fdbbcad896511be508e1ca1a64e080717c718.zip
CVE-2013-1752: poplib: Limit maximum line lengths to 2048
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. Change-Id: I3a9b6c76afba85f7c18de5a368df2dc96b534b55 Signed-off-by: Chanho Park <chanho61.park@samsung.com>
-rw-r--r--Lib/poplib.py11
-rw-r--r--Lib/test/test_poplib.py6
2 files changed, 15 insertions, 2 deletions
diff --git a/Lib/poplib.py b/Lib/poplib.py
index dc7cbdf..d03330f 100644
--- a/Lib/poplib.py
+++ b/Lib/poplib.py
@@ -32,6 +32,12 @@ CR = '\r'
LF = '\n'
CRLF = CR+LF
+# maximal line length when calling readline(). This is to prevent
+# reading arbitrary lenght lines. RFC 1939 limits POP3 line length to
+# 512 characters, including CRLF. We have selected 2048 just to be on
+# the safe side.
+_MAXLINE = 2048
+
class POP3:
@@ -103,7 +109,10 @@ class POP3:
# Raise error_proto('-ERR EOF') if the connection is closed.
def _getline(self):
- line = self.file.readline()
+ line = self.file.readline(_MAXLINE + 1)
+ if len(line) > _MAXLINE:
+ raise error_proto('line too long')
+
if self._debugging > 1: print '*get*', repr(line)
if not line: raise error_proto('-ERR EOF')
octets = len(line)
diff --git a/Lib/test/test_poplib.py b/Lib/test/test_poplib.py
index af48fdd..7a7d7d9 100644
--- a/Lib/test/test_poplib.py
+++ b/Lib/test/test_poplib.py
@@ -81,7 +81,7 @@ class DummyPOP3Handler(asynchat.async_chat):
def cmd_list(self, arg):
if arg:
- self.push('+OK %s %s' %(arg, arg))
+ self.push('+OK %s %s' % (arg, arg))
else:
self.push('+OK')
asynchat.async_chat.push(self, LIST_RESP)
@@ -198,6 +198,10 @@ class TestPOP3Class(TestCase):
113)
self.assertEqual(self.client.retr('foo'), expected)
+ def test_too_long_lines(self):
+ self.assertRaises(poplib.error_proto, self.client._shortcmd,
+ 'echo +%s' % ((poplib._MAXLINE + 10) * 'a'))
+
def test_dele(self):
self.assertOK(self.client.dele('foo'))