[Python-checkins] cpython (2.6): - Issue #16037: HTTPMessage.readheaders() raises an HTTPException when more
barry.warsaw
python-checkins at python.org
Sun Sep 29 20:01:32 CEST 2013
http://hg.python.org/cpython/rev/582e5072ff89
changeset: 85861:582e5072ff89
branch: 2.6
parent: 85797:8b19e7d0be45
user: Barry Warsaw <barry at python.org>
date: Sun Sep 29 13:59:06 2013 -0400
summary:
- Issue #16037: HTTPMessage.readheaders() raises an HTTPException when more
than 100 headers are read. Adapted from patch by Jyrki Pulliainen.
files:
Lib/httplib.py | 7 +++++++
Lib/test/test_httplib.py | 7 +++++++
Misc/NEWS | 3 +++
3 files changed, 17 insertions(+), 0 deletions(-)
diff --git a/Lib/httplib.py b/Lib/httplib.py
--- a/Lib/httplib.py
+++ b/Lib/httplib.py
@@ -211,6 +211,10 @@
# maximal amount of data to read at one time in _safe_read
MAXAMOUNT = 1048576
+# maximum amount of headers accepted
+_MAXHEADERS = 100
+
+
class HTTPMessage(mimetools.Message):
def addheader(self, key, value):
@@ -267,6 +271,8 @@
elif self.seekable:
tell = self.fp.tell
while True:
+ if len(hlist) > _MAXHEADERS:
+ raise HTTPException("got more than %d headers" % _MAXHEADERS)
if tell:
try:
startofline = tell()
@@ -1203,6 +1209,7 @@
self.args = line,
self.line = line
+
# for backwards compatibility
error = HTTPException
diff --git a/Lib/test/test_httplib.py b/Lib/test/test_httplib.py
--- a/Lib/test/test_httplib.py
+++ b/Lib/test/test_httplib.py
@@ -152,6 +152,13 @@
if resp.read() != "":
self.fail("Did not expect response from HEAD request")
+ def test_too_many_headers(self):
+ headers = '\r\n'.join('Header%d: foo' % i for i in xrange(200)) + '\r\n'
+ text = ('HTTP/1.1 200 OK\r\n' + headers)
+ s = FakeSocket(text)
+ r = httplib.HTTPResponse(s)
+ self.assertRaises(httplib.HTTPException, r.begin)
+
def test_send_file(self):
expected = 'GET /foo HTTP/1.1\r\nHost: example.com\r\n' \
'Accept-Encoding: identity\r\nContent-Length:'
diff --git a/Misc/NEWS b/Misc/NEWS
--- a/Misc/NEWS
+++ b/Misc/NEWS
@@ -13,6 +13,9 @@
Library
-------
+- Issue #16037: HTTPMessage.readheaders() raises an HTTPException when more
+ than 100 headers are read. Adapted from patch by Jyrki Pulliainen.
+
- Issue #16038: CVE-2013-1752: ftplib: Limit amount of data read by
limiting the call to readline(). Original patch by Michał
Jastrzębski and Giampaolo Rodola.
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list