]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
http: read final crlf of chunked requests 2225/head
authorPierce Lopez <pierce.lopez@gmail.com>
Tue, 26 Dec 2017 03:11:26 +0000 (22:11 -0500)
committerPierce Lopez <pierce.lopez@gmail.com>
Tue, 26 Dec 2017 03:11:26 +0000 (22:11 -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 de8d8bf383ee6a440f3aa1306e85f19e19f34e5f..331386a158ac4b073e1cff161962b1b87e974f7c 100644 (file)
@@ -599,6 +599,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 1b1286022602ca5f8864a7acf0967d5d86d763c6..3b0524940ab1627b59046d213dd960dd9054d939 100644 (file)
@@ -808,9 +808,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 7e3ac7c258a71e6f108b380a687714ef53bd6e51..46390e0d118a32545429a05ff7f343f263e254e8 100644 (file)
@@ -2138,7 +2138,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.