File tree 3 files changed +19
-2
lines changed
3 files changed +19
-2
lines changed Original file line number Diff line number Diff line change @@ -32,6 +32,12 @@ class error_proto(Exception): pass
32
32
LF = b'\n '
33
33
CRLF = CR + LF
34
34
35
+ # maximal line length when calling readline(). This is to prevent
36
+ # reading arbitrary lenght lines. RFC 1939 limits POP3 line length to
37
+ # 512 characters, including CRLF. We have selected 2048 just to be on
38
+ # the safe side.
39
+ _MAXLINE = 2048
40
+
35
41
36
42
class POP3 :
37
43
@@ -107,7 +113,10 @@ def _putcmd(self, line):
107
113
# Raise error_proto('-ERR EOF') if the connection is closed.
108
114
109
115
def _getline (self ):
110
- line = self .file .readline ()
116
+ line = self .file .readline (_MAXLINE + 1 )
117
+ if len (line ) > _MAXLINE :
118
+ raise error_proto ('line too long' )
119
+
111
120
if self ._debugging > 1 : print ('*get*' , repr (line ))
112
121
if not line : raise error_proto ('-ERR EOF' )
113
122
octets = len (line )
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ def cmd_stat(self, arg):
83
83
84
84
def cmd_list (self , arg ):
85
85
if arg :
86
- self .push ('+OK %s %s' % (arg , arg ))
86
+ self .push ('+OK %s %s' % (arg , arg ))
87
87
else :
88
88
self .push ('+OK' )
89
89
asynchat .async_chat .push (self , LIST_RESP )
@@ -204,6 +204,10 @@ def test_retr(self):
204
204
foo = self .client .retr ('foo' )
205
205
self .assertEqual (foo , expected )
206
206
207
+ def test_too_long_lines (self ):
208
+ self .assertRaises (poplib .error_proto , self .client ._shortcmd ,
209
+ 'echo +%s' % ((poplib ._MAXLINE + 10 ) * 'a' ))
210
+
207
211
def test_dele (self ):
208
212
self .assertOK (self .client .dele ('foo' ))
209
213
Original file line number Diff line number Diff line change @@ -10,6 +10,10 @@ What's New in Python 3.2.6?
10
10
Library
11
11
-------
12
12
13
+ - Issue #16041: CVE-2013-1752: poplib: Limit maximum line lengths to 2048 to
14
+ prevent readline() calls from consuming too much memory. Patch by Jyrki
15
+ Pulliainen.
16
+
13
17
- Issue #16042: CVE-2013-1752: smtplib: Limit amount of data read by
14
18
limiting the call to readline(). Original patch by Christian Heimes.
15
19
You can’t perform that action at this time.
0 commit comments