[Python-bugs-list] [Bug #125744] httplib does not check if port is valid (easy to fix?)
noreply@sourceforge.net
noreply@sourceforge.net
Thu, 14 Dec 2000 06:37:12 -0800
Bug #125744, was updated on 2000-Dec-13 20:45
Here is a current snapshot of the bug.
Project: Python
Category: Python Library
Status: Open
Resolution: None
Bug Group: None
Priority: 5
Submitted by: dealfaro
Assigned to : nobody
Summary: httplib does not check if port is valid (easy to fix?)
Details: In httplib.py, line 336, the following code appears:
def _set_hostport(self, host, port):
if port is None:
i = string.find(host, ':')
if i >= 0:
port = int(host[i+1:])
host = host[:i]
else:
port = self.default_port
self.host = host
self.port = port
Ths code breaks if the host string ends with ":", so that
int("") is called. In the old (1.5.2) version of this
module, the corresponding int () conversion used to be
enclosed in a try/except pair:
try: port = string.atoi(port)
except string.atoi_error:
raise socket.error, "nonnumeric port"
and this fixed the problem.
Note BTW that now the error reported by int is
"ValueError: invalid literal for int():"
rather than the above string.atoi_error.
I found this problem while downloading web pages,
but unfortunately I cannot pinpoint which page
caused the problem.
Luca de Alfaro
Follow-Ups:
Date: 2000-Dec-14 06:37
By: gvanrossum
Comment:
The only effect is that it raises ValueError instead of socket.error.
Where is this a problem?
(Note that string.atoi_error is an alias for ValueError.)
-------------------------------------------------------
For detailed info, follow this link:
http://sourceforge.net/bugs/?func=detailbug&bug_id=125744&group_id=5470