cpython: 7214e3324a45 (original) (raw)

Mercurial > cpython

changeset 85889:7214e3324a45 2.6

- Issue #16041: CVE-2013-1752: poplib: Limit maximum line lengths to 2048 to prevent readline() calls from consuming too much member. Patch by Jyrki Pulliainen. [#16041]

Barry Warsaw barry@python.org
date Mon, 30 Sep 2013 15:56:29 -0400
parents 582e5072ff89
children 39dbcc92b6c0 3f09756916ce
files Lib/poplib.py Lib/test/test_poplib.py Misc/NEWS
diffstat 3 files changed, 95 insertions(+), 7 deletions(-)[+] [-] Lib/poplib.py 14 Lib/test/test_poplib.py 71 Misc/NEWS 17

line wrap: on

line diff

--- 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 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: @@ -103,7 +109,10 @@ class POP3: # Raise error_proto('-ERR EOF') if the connection is closed. def _getline(self):

+ if self._debugging > 1: print 'get', repr(line) if not line: raise error_proto('-ERR EOF') octets = len(line) @@ -363,7 +372,10 @@ else: line = "" renewline = re.compile(r'.*?\n') match = renewline.match(self.buffer) + while not match:

--- a/Lib/test/test_poplib.py +++ b/Lib/test/test_poplib.py @@ -1,3 +1,4 @@ +import os import socket import threading import poplib @@ -21,6 +22,34 @@ def server(evt, serv): serv.close() evt.set() + +def evil_server(evt, serv, use_ssl=False):

+ + class GeneralTests(TestCase): def setUp(self): @@ -65,8 +94,50 @@ class GeneralTests(TestCase): pop.sock.close() +class EvilServerTests(TestCase):

+

+

+

+ + +SUPPORTS_SSL = False + +if hasattr(poplib, 'POP3_SSL'):

+

+

+

+ + def test_main(verbose=None): test_support.run_unittest(GeneralTests)

+

if name == 'main': test_main()

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -13,15 +13,22 @@ Core and Builtins Library ------- -- Issue #16037: HTTPMessage.readheaders() raises an HTTPException when more