diff options
author | Georg Brandl <georg@python.org> | 2014-10-12 08:50:11 +0200 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-10-12 08:50:11 +0200 |
commit | b3ac84322fe6dd542aa755779cdbc155edca8064 (patch) | |
tree | 6824b682fa75935c42a3faefc3e7abf11483a274 /Lib/nntplib.py | |
parent | f84422da1dd651fc9f0b474f3cd955b6baf2bdcc (diff) | |
download | cpython-git-b3ac84322fe6dd542aa755779cdbc155edca8064.tar.gz |
#16040: fix unlimited read from connection in nntplib.
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 32bffd8e27..0d4bbbbaab 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""" @@ -410,7 +417,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 |