[2.7] bpo-30119: fix ftplib.FTP.putline() to throw an error for a illegal command (#1214) (#2894)
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index 153647b..6644554 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -171,6 +171,8 @@
# Internal: send one line to the server, appending CRLF
def putline(self, line):
+ if '\r' in line or '\n' in line:
+ raise ValueError('an illegal newline character should not be contained')
line = line + CRLF
if self.debugging > 1: print '*put*', self.sanitize(line)
self.sock.sendall(line)
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index 044ce45..fdfa313 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -439,6 +439,9 @@
self.assertEqual(self.client.sanitize('PASS 12345'), repr('PASS *****'))
def test_exceptions(self):
+ self.assertRaises(ValueError, self.client.sendcmd, 'echo 40\r\n0')
+ self.assertRaises(ValueError, self.client.sendcmd, 'echo 40\n0')
+ self.assertRaises(ValueError, self.client.sendcmd, 'echo 40\r0')
self.assertRaises(ftplib.error_temp, self.client.sendcmd, 'echo 400')
self.assertRaises(ftplib.error_temp, self.client.sendcmd, 'echo 499')
self.assertRaises(ftplib.error_perm, self.client.sendcmd, 'echo 500')