Skip to content

Commit

Permalink
[3.6] bpo-30119: fix ftplib.FTP.putline() to throw an error for a ill…
Browse files Browse the repository at this point in the history
…egal command (#1214) (#2886)
  • Loading branch information
corona10 authored and vstinner committed Jul 26, 2017
1 parent c52cea4 commit 8c2d4cf
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Lib/ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_ftplib.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,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')
Expand All @@ -492,7 +495,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')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ftplib.FTP.putline() now throws ValueError on commands that contains CR or
LF. Patch by Dong-hee Na.

0 comments on commit 8c2d4cf

Please sign in to comment.