summaryrefslogtreecommitdiffstats
path: root/Lib/test
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/test
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/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 47563c8..c0b537a 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -92,6 +92,7 @@ class DummyFTPHandler(asynchat.async_chat):
self.next_response = ''
self.next_data = None
self.rest = None
+ self.next_retr_data = RETR_DATA
self.push('220 welcome')
def collect_incoming_data(self, data):
@@ -221,7 +222,7 @@ class DummyFTPHandler(asynchat.async_chat):
offset = int(self.rest)
else:
offset = 0
- self.dtp.push(RETR_DATA[offset:])
+ self.dtp.push(self.next_retr_data[offset:])
self.dtp.close_when_done()
self.rest = None
@@ -243,6 +244,11 @@ class DummyFTPHandler(asynchat.async_chat):
self.dtp.push(MLSD_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):
@@ -759,6 +765,20 @@ class TestFTPClass(TestCase):
self.assertEqual(ftplib.parse257('257 "/foo/b""ar"'), '/foo/b"ar')
self.assertEqual(ftplib.parse257('257 "/foo/b""ar" created'), '/foo/b"ar')
+ 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 = io.BytesIO(b'x' * self.client.maxline * 2)
+ self.assertRaises(ftplib.Error, self.client.storlines, 'stor', f)
+
class TestIPv6Environment(TestCase):