File tree 4 files changed +18
-2
lines changed
4 files changed +18
-2
lines changed Original file line number Diff line number Diff line change @@ -169,8 +169,8 @@ The following exceptions are raised as appropriate:
169
169
A subclass of :exc: `HTTPException `. Raised if a server responds with a HTTP
170
170
status code that we don't understand.
171
171
172
- The constants defined in this module are:
173
172
173
+ The constants defined in this module are:
174
174
175
175
.. data :: HTTP_PORT
176
176
Original file line number Diff line number Diff line change 206
206
207
207
# maximal line length when calling readline().
208
208
_MAXLINE = 65536
209
+ _MAXHEADERS = 100
210
+
209
211
210
212
class HTTPMessage (email .message .Message ):
211
213
# XXX The only usage of this method is in
@@ -253,6 +255,8 @@ def parse_headers(fp, _class=HTTPMessage):
253
255
if len (line ) > _MAXLINE :
254
256
raise LineTooLong ("header line" )
255
257
headers .append (line )
258
+ if len (headers ) > _MAXHEADERS :
259
+ raise HTTPException ("got more than %d headers" % _MAXHEADERS )
256
260
if line in (b'\r \n ' , b'\n ' , b'' ):
257
261
break
258
262
hstring = b'' .join (headers ).decode ('iso-8859-1' )
Original file line number Diff line number Diff line change @@ -272,6 +272,15 @@ def test_read_head(self):
272
272
if resp .read ():
273
273
self .fail ("Did not expect response from HEAD request" )
274
274
275
+ def test_too_many_headers (self ):
276
+ headers = '\r \n ' .join ('Header%d: foo' % i
277
+ for i in range (client ._MAXHEADERS + 1 )) + '\r \n '
278
+ text = ('HTTP/1.1 200 OK\r \n ' + headers )
279
+ s = FakeSocket (text )
280
+ r = client .HTTPResponse (s )
281
+ self .assertRaisesRegex (client .HTTPException ,
282
+ r"got more than \d+ headers" , r .begin )
283
+
275
284
def test_send_file (self ):
276
285
expected = (b'GET /foo HTTP/1.1\r \n Host: example.com\r \n '
277
286
b'Accept-Encoding: identity\r \n Content-Length:' )
Original file line number Diff line number Diff line change 1
- ++++++++++
1
+ +++++++++++
2
2
Python News
3
3
+++++++++++
4
4
@@ -10,6 +10,9 @@ What's New in Python 3.2.6?
10
10
Library
11
11
-------
12
12
13
+ - Issue #16037: HTTPMessage.readheaders() raises an HTTPException when more than
14
+ 100 headers are read. Adapted from patch by Jyrki Pulliainen.
15
+
13
16
- Issue #18709: Fix CVE-2013-4238. The SSL module now handles NULL bytes
14
17
inside subjectAltName correctly. Formerly the module has used OpenSSL's
15
18
GENERAL_NAME_print() function to get the string represention of ASN.1
You can’t perform that action at this time.
0 commit comments