diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2013-10-20 16:58:27 +0300 |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2013-10-20 16:58:27 +0300 |
commit | 7433ee7b17734553822317cfcbd2ec6e98867438 (patch) | |
tree | c9a90e32944a392c5f1ad5435d335aacabb74af5 /Lib/test/test_ftplib.py | |
parent | c50db66c6b75ff38d693b2dc06b1c84eb4d795a6 (diff) | |
download | cpython-7433ee7b17734553822317cfcbd2ec6e98867438.tar.gz |
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.py | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py index 2c45af3145..4686183618 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): |