diff options
author | Georg Brandl <georg@python.org> | 2013-10-27 06:23:53 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2013-10-27 06:23:53 (GMT) |
commit | 7e27abbb3936e9a7baea13ceeac6abd256bc0d6f (patch) | |
tree | 6ee857cd02820aa984dddf6d9b8c5fc21cb9ffbe /Lib/poplib.py | |
parent | 72c98d3a761457a4f2b8054458b19f051dfb5886 (diff) | |
download | cpython-7e27abbb3936e9a7baea13ceeac6abd256bc0d6f.zip cpython-7e27abbb3936e9a7baea13ceeac6abd256bc0d6f.tar.gz cpython-7e27abbb3936e9a7baea13ceeac6abd256bc0d6f.tar.bz2 |
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.
Diffstat (limited to 'Lib/poplib.py')
-rw-r--r-- | Lib/poplib.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/poplib.py b/Lib/poplib.py index 84f1889..43f8305 100644 --- a/Lib/poplib.py +++ b/Lib/poplib.py @@ -32,6 +32,12 @@ CR = b'\r' LF = b'\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: @@ -107,7 +113,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) |