summaryrefslogtreecommitdiffstats
path: root/Lib/ftplib.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-10-20 14:02:10 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-10-20 14:02:10 (GMT)
commit2acc456c334460a7430e386772d1c48b1e0e7c7f (patch)
treef0a7dd810c81944e3a997ef15a8877ba9242d78c /Lib/ftplib.py
parent6de9200e5716d969b1f4a125eed2fbbb2f3acff7 (diff)
parentc30b178cbc92e62c22527cd7e1af2f02723ba679 (diff)
downloadcpython-2acc456c334460a7430e386772d1c48b1e0e7c7f.zip
cpython-2acc456c334460a7430e386772d1c48b1e0e7c7f.tar.gz
cpython-2acc456c334460a7430e386772d1c48b1e0e7c7f.tar.bz2
Issue #16038: CVE-2013-1752: ftplib: Limit amount of data read by
limiting the call to readline(). Original patch by Michał Jastrzębski and Giampaolo Rodola.
Diffstat (limited to 'Lib/ftplib.py')
-rw-r--r--Lib/ftplib.py15
1 files changed, 12 insertions, 3 deletions
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index fcd4b14..9538fec 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -50,6 +50,8 @@ MSG_OOB = 0x1 # Process data out of band
# The standard FTP server control port
FTP_PORT = 21
+# The sizehint parameter passed to readline() calls
+MAXLINE = 8192
# Exception raised when an error or invalid response is received
@@ -97,6 +99,7 @@ class FTP:
debugging = 0
host = ''
port = FTP_PORT
+ maxline = MAXLINE
sock = None
file = None
welcome = None
@@ -197,7 +200,9 @@ class FTP:
# Internal: return one line from the server, stripping CRLF.
# Raise EOFError if the connection is closed
def getline(self):
- line = self.file.readline()
+ line = self.file.readline(self.maxline + 1)
+ if len(line) > self.maxline:
+ raise Error("got more than %d bytes" % self.maxline)
if self.debugging > 1:
print('*get*', self.sanitize(line))
if not line:
@@ -463,7 +468,9 @@ class FTP:
with self.transfercmd(cmd) as conn, \
conn.makefile('r', encoding=self.encoding) as fp:
while 1:
- line = fp.readline()
+ line = fp.readline(self.maxline + 1)
+ if len(line) > self.maxline:
+ raise Error("got more than %d bytes" % self.maxline)
if self.debugging > 2:
print('*retr*', repr(line))
if not line:
@@ -522,7 +529,9 @@ class FTP:
self.voidcmd('TYPE A')
with self.transfercmd(cmd) as conn:
while 1:
- buf = fp.readline()
+ buf = fp.readline(self.maxline + 1)
+ if len(buf) > self.maxline:
+ raise Error("got more than %d bytes" % self.maxline)
if not buf:
break
if buf[-2:] != B_CRLF: