diff options
author | Georg Brandl <georg@python.org> | 2014-01-25 09:02:18 +0100 |
---|---|---|
committer | Georg Brandl <georg@python.org> | 2014-01-25 09:02:18 +0100 |
commit | c11435399e7af8317e5a51642ee665347da2b97f (patch) | |
tree | 45a63ff03df5fda7b9e3c697331165ea5b22bbc0 /Lib/test/mock_socket.py | |
parent | f580d5b6f7468abf768a2ee6360168ad92893457 (diff) | |
download | cpython-git-c11435399e7af8317e5a51642ee665347da2b97f.tar.gz |
#16042: CVE-2013-1752: smtplib fix for unlimited readline() from socket
Diffstat (limited to 'Lib/test/mock_socket.py')
-rw-r--r-- | Lib/test/mock_socket.py | 9 |
1 files changed, 7 insertions, 2 deletions
diff --git a/Lib/test/mock_socket.py b/Lib/test/mock_socket.py index d09e78c1d5..861bfb2b56 100644 --- a/Lib/test/mock_socket.py +++ b/Lib/test/mock_socket.py @@ -21,8 +21,13 @@ class MockFile: """ def __init__(self, lines): self.lines = lines - def readline(self): - return self.lines.pop(0) + b'\r\n' + def readline(self, limit=-1): + result = self.lines.pop(0) + b'\r\n' + if limit >= 0: + # Re-insert the line, removing the \r\n we added. + self.lines.insert(0, result[limit:-2]) + result = result[:limit] + return result def close(self): pass |