[Python-checkins] bpo-30119: fix ftplib.FTP.putline() to throw an error for a illegal command (#1214)
Giampaolo Rodola
webhook-mailer at python.org
Sat Jul 22 13:20:25 EDT 2017
https://github.com/python/cpython/commit/2b1e6e9696cb433c0e0da11145157d54275d119f
commit: 2b1e6e9696cb433c0e0da11145157d54275d119f
branch: master
author: Dong-hee Na <donghee.na92 at gmail.com>
committer: Giampaolo Rodola <g.rodola at gmail.com>
date: 2017-07-22T19:20:22+02:00
summary:
bpo-30119: fix ftplib.FTP.putline() to throw an error for a illegal command (#1214)
files:
M Lib/ftplib.py
M Lib/test/test_ftplib.py
M Misc/NEWS
diff --git a/Lib/ftplib.py b/Lib/ftplib.py
index 8f36f537e8a..a02e595cb02 100644
--- a/Lib/ftplib.py
+++ b/Lib/ftplib.py
@@ -186,6 +186,8 @@ def sanitize(self, s):
# 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))
diff --git a/Lib/test/test_ftplib.py b/Lib/test/test_ftplib.py
index 6571816bfdf..24ea382ff29 100644
--- a/Lib/test/test_ftplib.py
+++ b/Lib/test/test_ftplib.py
@@ -485,6 +485,9 @@ def test_sanitize(self):
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')
@@ -493,7 +496,8 @@ def test_exceptions(self):
def test_all_errors(self):
exceptions = (ftplib.error_reply, ftplib.error_temp, ftplib.error_perm,
- ftplib.error_proto, ftplib.Error, OSError, EOFError)
+ ftplib.error_proto, ftplib.Error, OSError,
+ EOFError)
for x in exceptions:
try:
raise x('exception not included in all_errors set')
diff --git a/Misc/NEWS b/Misc/NEWS
index ce4874ac36d..38449c0409f 100644
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -376,6 +376,9 @@ Extension Modules
Library
-------
+- bpo-30119: ftplib.FTP.putline() now throws ValueError on commands that contains
+ CR or LF. Patch by Dong-hee Na.
+
- bpo-30879: os.listdir() and os.scandir() now emit bytes names when called
with bytes-like argument.
More information about the Python-checkins
mailing list