]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
http: read final crlf of chunked requests
authorPierce Lopez <pierce.lopez@gmail.com>
Tue, 26 Dec 2017 03:11:26 +0000 (22:11 -0500)
committerBen Darnell <ben@bendarnell.com>
Fri, 5 Jan 2018 03:13:12 +0000 (22:13 -0500)
otherwise a subsequent request on the same connection
will fail to be parsed

thanks to @eeelin for the bug report

tornado/http1connection.py
tornado/test/httpserver_test.py
tornado/test/web_test.py

index 20d98e437d71154cf58d7d98f1defbda4d9f357e..9b33c94ed10f26fe782181434327eef033b06bc8 100644 (file)
@@ -593,6 +593,9 @@ class HTTP1Connection(httputil.HTTPConnection):
             chunk_len = yield self.stream.read_until(b"\r\n", max_bytes=64)
             chunk_len = int(chunk_len.strip(), 16)
             if chunk_len == 0:
+                crlf = yield self.stream.read_bytes(2)
+                if crlf != b'\r\n':
+                    raise HTTPInputError("improperly terminated chunked request")
                 return
             total_size += chunk_len
             if total_size > self._max_body_size:
index 11cb72313765905e20dc59e9e2bf80e4ce2a43e8..59eb6fd1ef1d70ae35a0b8f8e7b73e8f40697335 100644 (file)
@@ -786,9 +786,12 @@ class KeepAliveTest(AsyncHTTPTestCase):
     def test_keepalive_chunked(self):
         self.http_version = b'HTTP/1.0'
         self.connect()
-        self.stream.write(b'POST / HTTP/1.0\r\nConnection: keep-alive\r\n'
+        self.stream.write(b'POST / HTTP/1.0\r\n'
+                          b'Connection: keep-alive\r\n'
                           b'Transfer-Encoding: chunked\r\n'
-                          b'\r\n0\r\n')
+                          b'\r\n'
+                          b'0\r\n'
+                          b'\r\n')
         self.read_response()
         self.assertEqual(self.headers['Connection'], 'Keep-Alive')
         self.stream.write(b'GET / HTTP/1.0\r\nConnection: keep-alive\r\n\r\n')
index d79ea52c1be27111e387f1a23bbd8c5954ae2258..d83446e4286cc993680ac5ee3199a108795936fd 100644 (file)
@@ -2134,7 +2134,7 @@ class StreamingRequestBodyTest(WebTestCase):
         stream.write(b"4\r\nqwer\r\n")
         data = yield self.data
         self.assertEquals(data, b"qwer")
-        stream.write(b"0\r\n")
+        stream.write(b"0\r\n\r\n")
         yield self.finished
         data = yield gen.Task(stream.read_until_close)
         # This would ideally use an HTTP1Connection to read the response.