summaryrefslogtreecommitdiffstats
path: root/meta/recipes-devtools/python/python/python-2.7.3-CVE-2013-1752-httplib-fix.patch
blob: e68f53f4bc50b6d7634778e23f8e3c6a92c6e106 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
Upstream-Status: Backport

CVE-2013-1752: httplib: HTTPMessage.readheaders() raises an HTTPException 
when more than 100 headers are read.
Patch by Jyrki Pulliainen and Daniel Eriksson.

Signed-off-by: Tudor Florea <tudor.florea@enea.com>
---
diff -r 133ee2b48e52 Lib/httplib.py
--- a/Lib/httplib.py	Fri Aug 01 23:51:51 2014 -0700
+++ b/Lib/httplib.py	Sat Aug 02 13:59:25 2014 +0000
@@ -214,6 +214,7 @@
 
 # maximal line length when calling readline().
 _MAXLINE = 65536
+_MAXHEADERS = 100
 
 class HTTPMessage(mimetools.Message):
 
@@ -271,6 +272,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()
diff -r 133ee2b48e52 Lib/test/test_httplib.py
--- a/Lib/test/test_httplib.py	Fri Aug 01 23:51:51 2014 -0700
+++ b/Lib/test/test_httplib.py	Sat Aug 02 13:59:25 2014 +0000
@@ -262,6 +262,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:'