diff options
author | Georg Brandl <georg@python.org> | 2013-10-27 06:29:47 (GMT) |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2013-10-27 06:29:47 (GMT) |
commit | 28e78414f9175774f26d8c564c7c1d3b078f99de (patch) | |
tree | c7d39909d04b0b9f313083b4c8e9da197662c397 /Lib/nntplib.py | |
parent | 7e27abbb3936e9a7baea13ceeac6abd256bc0d6f (diff) | |
download | cpython-28e78414f9175774f26d8c564c7c1d3b078f99de.zip cpython-28e78414f9175774f26d8c564c7c1d3b078f99de.tar.gz cpython-28e78414f9175774f26d8c564c7c1d3b078f99de.tar.bz2 |
Issue #16040: CVE-2013-1752: nntplib: Limit maximum line lengths to 2048 to
prevent readline() calls from consuming too much memory. Patch by Jyrki
Pulliainen.
Diffstat (limited to 'Lib/nntplib.py')
-rw-r--r-- | Lib/nntplib.py | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/Lib/nntplib.py b/Lib/nntplib.py index 2de6ebd..02cc37c 100644 --- a/Lib/nntplib.py +++ b/Lib/nntplib.py @@ -85,6 +85,13 @@ __all__ = ["NNTP", "decode_header", ] +# maximal line length when calling readline(). This is to prevent +# reading arbitrary lenght lines. RFC 3977 limits NNTP line length to +# 512 characters, including CRLF. We have selected 2048 just to be on +# the safe side. +_MAXLINE = 2048 + + # Exceptions raised when an error or invalid response is received class NNTPError(Exception): """Base class for all nntplib exceptions""" @@ -424,7 +431,9 @@ class _NNTPBase: """Internal: return one line from the server, stripping _CRLF. Raise EOFError if the connection is closed. Returns a bytes object.""" - line = self.file.readline() + line = self.file.readline(_MAXLINE +1) + if len(line) > _MAXLINE: + raise NNTPDataError('line too long') if self.debugging > 1: print('*get*', repr(line)) if not line: raise EOFError |