File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,6 +32,12 @@ class error_proto(Exception): pass
3232LF = b'\n '
3333CRLF = CR + LF
3434
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+
3541
3642class POP3 :
3743
@@ -107,7 +113,10 @@ def _putcmd(self, line):
107113 # Raise error_proto('-ERR EOF') if the connection is closed.
108114
109115 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+
111120 if self ._debugging > 1 : print ('*get*' , repr (line ))
112121 if not line : raise error_proto ('-ERR EOF' )
113122 octets = len (line )
Original file line number Diff line number Diff line change @@ -83,7 +83,7 @@ def cmd_stat(self, arg):
8383
8484 def cmd_list (self , arg ):
8585 if arg :
86- self .push ('+OK %s %s' % (arg , arg ))
86+ self .push ('+OK %s %s' % (arg , arg ))
8787 else :
8888 self .push ('+OK' )
8989 asynchat .async_chat .push (self , LIST_RESP )
@@ -208,6 +208,10 @@ def test_retr(self):
208208 foo = self .client .retr ('foo' )
209209 self .assertEqual (foo , expected )
210210
211+ def test_too_long_lines (self ):
212+ self .assertRaises (poplib .error_proto , self .client ._shortcmd ,
213+ 'echo +%s' % ((poplib ._MAXLINE + 10 ) * 'a' ))
214+
211215 def test_dele (self ):
212216 self .assertOK (self .client .dele ('foo' ))
213217
Original file line number Diff line number Diff line change @@ -81,6 +81,10 @@ Core and Builtins
8181Library
8282-------
8383
84+ - Issue #16041: CVE-2013-1752: poplib: Limit maximum line lengths to 2048 to
85+ prevent readline() calls from consuming too much memory. Patch by Jyrki
86+ Pulliainen.
87+
8488- Issue #17997: Change behavior of ``ssl.match_hostname()`` to follow RFC 6125,
8589 for security reasons. It now doesn't match multiple wildcards nor wildcards
8690 inside IDN fragments.
You can’t perform that action at this time.
0 commit comments