]> granicus.if.org Git - python/commitdiff
[2.7] bpo-30119: fix ftplib.FTP.putline() to throw an error for a illegal command...
authorDong-hee Na <donghee.na92@gmail.com>
Wed, 26 Jul 2017 15:50:36 +0000 (00:50 +0900)
committerVictor Stinner <victor.stinner@gmail.com>
Wed, 26 Jul 2017 15:50:36 +0000 (17:50 +0200)
Lib/ftplib.py
Lib/test/test_ftplib.py
Misc/NEWS.d/next/Library/2017-07-26-22-02-07.bpo-30119.DZ6C_S.rst [new file with mode: 0644]

index 153647ba758ee0d710d1e0ec18c23dbdfd4580e6..6644554792791bdd5357882214db150820784014 100644 (file)
@@ -171,6 +171,8 @@ class FTP:
 
     # 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)
index 044ce4594c971fdcb834b102d650a0667bee6aad..fdfa31387cb4b999c1dfe09e50095d3e6d2c84ca 100644 (file)
@@ -439,6 +439,9 @@ class TestFTPClass(TestCase):
         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')
diff --git a/Misc/NEWS.d/next/Library/2017-07-26-22-02-07.bpo-30119.DZ6C_S.rst b/Misc/NEWS.d/next/Library/2017-07-26-22-02-07.bpo-30119.DZ6C_S.rst
new file mode 100644 (file)
index 0000000..a37d370
--- /dev/null
@@ -0,0 +1,2 @@
+ftplib.FTP.putline() now throws ValueError on commands that contains CR or
+LF. Patch by Dong-hee Na.