Commit 6c1bb7b4 authored by Barry Warsaw's avatar Barry Warsaw

- Issue #16037: HTTPMessage.readheaders() raises an HTTPException when more

  than 100 headers are read.  Adapted from patch by Jyrki Pulliainen.
parent d6fddf3d
...@@ -211,6 +211,10 @@ responses = { ...@@ -211,6 +211,10 @@ responses = {
# maximal amount of data to read at one time in _safe_read # maximal amount of data to read at one time in _safe_read
MAXAMOUNT = 1048576 MAXAMOUNT = 1048576
# maximum amount of headers accepted
_MAXHEADERS = 100
class HTTPMessage(mimetools.Message): class HTTPMessage(mimetools.Message):
def addheader(self, key, value): def addheader(self, key, value):
...@@ -267,6 +271,8 @@ class HTTPMessage(mimetools.Message): ...@@ -267,6 +271,8 @@ class HTTPMessage(mimetools.Message):
elif self.seekable: elif self.seekable:
tell = self.fp.tell tell = self.fp.tell
while True: while True:
if len(hlist) > _MAXHEADERS:
raise HTTPException("got more than %d headers" % _MAXHEADERS)
if tell: if tell:
try: try:
startofline = tell() startofline = tell()
...@@ -1203,6 +1209,7 @@ class BadStatusLine(HTTPException): ...@@ -1203,6 +1209,7 @@ class BadStatusLine(HTTPException):
self.args = line, self.args = line,
self.line = line self.line = line
# for backwards compatibility # for backwards compatibility
error = HTTPException error = HTTPException
......
...@@ -152,6 +152,13 @@ class BasicTest(TestCase): ...@@ -152,6 +152,13 @@ class BasicTest(TestCase):
if resp.read() != "": if resp.read() != "":
self.fail("Did not expect response from HEAD request") 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): def test_send_file(self):
expected = 'GET /foo HTTP/1.1\r\nHost: example.com\r\n' \ expected = 'GET /foo HTTP/1.1\r\nHost: example.com\r\n' \
'Accept-Encoding: identity\r\nContent-Length:' 'Accept-Encoding: identity\r\nContent-Length:'
......
...@@ -13,6 +13,9 @@ Core and Builtins ...@@ -13,6 +13,9 @@ Core and Builtins
Library 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 - Issue #16038: CVE-2013-1752: ftplib: Limit amount of data read by
limiting the call to readline(). Original patch by Michał limiting the call to readline(). Original patch by Michał
Jastrzębski and Giampaolo Rodola. Jastrzębski and Giampaolo Rodola.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment