summaryrefslogtreecommitdiffstats
path: root/Lib/test
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/test
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/test')
-rw-r--r--Lib/test/test_ftplib.py22
1 files changed, 21 insertions, 1 deletions
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index 1c2ceeb..2d5a814 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -46,6 +46,7 @@ class DummyFTPHandler(asynchat.async_chat):
self.last_received_cmd = None
self.last_received_data = ''
self.next_response = ''
+ self.next_retr_data = RETR_DATA
self.push('220 welcome')
def collect_incoming_data(self, data):
@@ -162,7 +163,7 @@ class DummyFTPHandler(asynchat.async_chat):
def cmd_retr(self, arg):
self.push('125 retr ok')
- self.dtp.push(RETR_DATA)
+ self.dtp.push(self.next_retr_data)
self.dtp.close_when_done()
def cmd_list(self, arg):
@@ -175,6 +176,11 @@ class DummyFTPHandler(asynchat.async_chat):
self.dtp.push(NLST_DATA)
self.dtp.close_when_done()
+ def cmd_setlongretr(self, arg):
+ # For testing. Next RETR will return long line.
+ self.next_retr_data = 'x' * int(arg)
+ self.push('125 setlongretr ok')
+
class DummyFTPServer(asyncore.dispatcher, threading.Thread):
@@ -362,6 +368,20 @@ class TestFTPClass(TestCase):
# IPv4 is in use, just make sure send_epsv has not been used
self.assertEqual(self.server.handler.last_received_cmd, 'pasv')
+ def test_line_too_long(self):
+ self.assertRaises(ftplib.Error, self.client.sendcmd,
+ 'x' * self.client.maxline * 2)
+
+ def test_retrlines_too_long(self):
+ self.client.sendcmd('SETLONGRETR %d' % (self.client.maxline * 2))
+ received = []
+ self.assertRaises(ftplib.Error,
+ self.client.retrlines, 'retr', received.append)
+
+ def test_storlines_too_long(self):
+ f = StringIO.StringIO('x' * self.client.maxline * 2)
+ self.assertRaises(ftplib.Error, self.client.storlines, 'stor', f)
+
class TestIPv6Environment(TestCase):