Skip to content

Commit

Permalink
[3.3] 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) (#2885)
  • Loading branch information
corona10 authored and ned-deily committed Jul 26, 2017
1 parent 7b92f9f commit a4e774f
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
2 changes: 2 additions & 0 deletions Lib/ftplib.py
Expand Up @@ -185,6 +185,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))
self.sock.sendall(line.encode(self.encoding))
Expand Down
6 changes: 5 additions & 1 deletion Lib/test/test_ftplib.py
Expand Up @@ -480,6 +480,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 @@ -488,7 +491,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, IOError, EOFError)
ftplib.error_proto, ftplib.Error, OSError,
EOFError)
for x in exceptions:
try:
raise x('exception not included in all_errors set')
Expand Down
3 changes: 3 additions & 0 deletions Misc/NEWS
Expand Up @@ -39,6 +39,9 @@ Core and Builtins
Library
-------

- bpo-30119: ftplib.FTP.putline() now throws ValueError on commands that contains
CR or LF. Patch by Dong-hee Na

- [Security] bpo-30730: Prevent environment variables injection in subprocess on
Windows. Prevent passing other invalid environment variables and command arguments.

Expand Down

0 comments on commit a4e774f

Please sign in to comment.