diff options
Diffstat (limited to 'Lib/poplib.py')
-rw-r--r-- | Lib/poplib.py | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/Lib/poplib.py b/Lib/poplib.py index dc7cbdf..b91e5f7 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 length 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,9 @@ 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) @@ -365,6 +373,8 @@ else: match = renewline.match(self.buffer) while not match: self._fillBuffer() + if len(self.buffer) > _MAXLINE: + raise error_proto('line too long') match = renewline.match(self.buffer) line = match.group(0) self.buffer = renewline.sub('' ,self.buffer, 1) |