summaryrefslogtreecommitdiffstats
path: root/Lib/ftplib.py
diff options
context:
space:
mode:
authorBarry Warsaw <barry@python.org>2013-09-25 13:36:58 (GMT)
committerBarry Warsaw <barry@python.org>2013-09-25 13:36:58 (GMT)
commitd6fddf3d15b5c7b012c919b48de6447d7a250f1c (patch)
treeb0d2e57ea25764cc0d4eff6e85b8aab03cb23cab /Lib/ftplib.py
parent4e95d601917b4429d41a5e437762d619608573c1 (diff)
downloadcpython-d6fddf3d15b5c7b012c919b48de6447d7a250f1c.zip
cpython-d6fddf3d15b5c7b012c919b48de6447d7a250f1c.tar.gz
cpython-d6fddf3d15b5c7b012c919b48de6447d7a250f1c.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. with test fixes by Serhiy Storchaka.
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 22decb2..a3c6475 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -54,6 +54,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
@@ -100,6 +102,7 @@ class FTP:
debugging = 0
host = ''
port = FTP_PORT
+ maxline = MAXLINE
sock = None
file = None
welcome = None
@@ -179,7 +182,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: raise EOFError
@@ -421,7 +426,9 @@ class FTP:
conn = self.transfercmd(cmd)
fp = conn.makefile('rb')
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:
break
@@ -473,7 +480,9 @@ class FTP:
self.voidcmd('TYPE A')
conn = self.transfercmd(cmd)
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:] != CRLF:
if buf[-1] in CRLF: buf = buf[:-1]