summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_ftplib.py
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2013-10-20 13:58:27 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2013-10-20 13:58:27 (GMT)
commitc30b178cbc92e62c22527cd7e1af2f02723ba679 (patch)
tree2a9c2b991a9dc2b2814c4a52e4672a2d6bf5d751 /Lib/test/test_ftplib.py
parent0abb21884c422d23013ebd0cbd2c37c09d4ea0c5 (diff)
downloadcpython-c30b178cbc92e62c22527cd7e1af2f02723ba679.zip
cpython-c30b178cbc92e62c22527cd7e1af2f02723ba679.tar.gz
cpython-c30b178cbc92e62c22527cd7e1af2f02723ba679.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/test_ftplib.py')
-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 2c45af3..4686183 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -91,6 +91,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):
@@ -220,7 +221,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
@@ -242,6 +243,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):
@@ -758,6 +764,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):