Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c88a6c7

Browse files
committed
SF bug #1168983: ftplib.py string index out of range
* resp[:1] in '123' # after Py2.2, this allowed blank responses to pass. * replace <> with != * provide a usage message for empty command line calls Backport candidate.
1 parent 714f878 commit c88a6c7

1 file changed

Lines changed: 16 additions & 7 deletions

File tree

Lib/ftplib.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,13 @@ def getresp(self):
208208
if self.debugging: print '*resp*', self.sanitize(resp)
209209
self.lastresp = resp[:3]
210210
c = resp[:1]
211+
if c in ('1', '2', '3'):
212+
return resp
211213
if c == '4':
212214
raise error_temp, resp
213215
if c == '5':
214216
raise error_perm, resp
215-
if c not in '123':
216-
raise error_proto, resp
217-
return resp
217+
raise error_proto, resp
218218

219219
def voidresp(self):
220220
"""Expect a response beginning with '2'."""
@@ -582,17 +582,17 @@ def parse229(resp, peer):
582582
Raises error_proto if it does not contain '(|||port|)'
583583
Return ('host.addr.as.numbers', port#) tuple.'''
584584

585-
if resp[:3] <> '229':
585+
if resp[:3] != '229':
586586
raise error_reply, resp
587587
left = resp.find('(')
588588
if left < 0: raise error_proto, resp
589589
right = resp.find(')', left + 1)
590590
if right < 0:
591591
raise error_proto, resp # should contain '(|||port|)'
592-
if resp[left + 1] <> resp[right - 1]:
592+
if resp[left + 1] != resp[right - 1]:
593593
raise error_proto, resp
594594
parts = resp[left + 1:right].split(resp[left+1])
595-
if len(parts) <> 5:
595+
if len(parts) != 5:
596596
raise error_proto, resp
597597
host = peer[0]
598598
port = int(parts[3])
@@ -755,7 +755,16 @@ def get_macro(self, macro):
755755

756756
def test():
757757
'''Test program.
758-
Usage: ftp [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ...'''
758+
Usage: ftp [-d] [-r[file]] host [-l[dir]] [-d[dir]] [-p] [file] ...
759+
760+
-d dir
761+
-l list
762+
-p password
763+
'''
764+
765+
if len(sys.argv) < 2:
766+
print test.__doc__
767+
sys.exit(0)
759768

760769
debugging = 0
761770
rcfile = None

0 commit comments

Comments
 (0)