1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/test
Sutou Kouhei 7965484434 Fix a bug that the last CRLF of chunked body may be used in the next request (#1812)
* Fix a bug that the last CRLF of chunked body may be used in the next request

The last CRLF of chunked body is checked by #1607. But it's
incomplete. If a client sends the last CRLF (or just LF) after Puma
processes "0\r\n" line, the last CRLF (or just LF) isn't dropped in
the "0\r\n" process:

675344e860/lib/puma/client.rb (L183-L192)

    if line.end_with?("\r\n")
      len = line.strip.to_i(16)
      if len == 0
        @body.rewind
        rest = io.read
        # rest is "" with no the last CRLF case and
        # "\r" with no last LF case.
        # rest.start_with?("\r\n") returns false for
        # Both of these cases.
        rest = rest[2..-1] if rest.start_with?("\r\n")
        @buffer = rest.empty? ? nil : rest
        set_ready
        return true
      end

The unprocessed last CRLF (or LF) is used as the first data in the
next request. Because Puma::Client#reset sets `@parsed_bytes`
to 0.

675344e860/lib/puma/client.rb (L100-L109)

    def reset(fast_check=true)
      @parsed_bytes = 0

It means that data in `@buffer` (it's "\r" in no the last LF case) and
unread data in input socket (it's "\r\n" in no the last CRLF case and
"\n" in no the last LF case) are used used as the first data in the
next request.

This change fixes these cases by the followings:

  * Ensures reading the last CRLF by setting `@partial_part_left` when
    CRLF isn't read in processing "0\r\n" line.

  * Introduces a `@in_last_chunk` new state to detect whether the last
    CRLF is waiting or not. It's reset in Puma::Client#reset.

* Remove unnecessary returns

https://github.com/puma/puma/pull/1812#discussion_r307806310 is the
location where this rule is made.

* Add missing last CRLF for chunked request in tests
2019-08-03 15:52:09 -07:00
..
config Allow to define a custom formatter for logs (#1816) 2019-08-01 12:21:23 -07:00
rackup [close #1802] Close listeners on SIGTERM 2019-05-30 15:16:51 -05:00
shell Add status to pumactl with pidfile (#1824) 2019-06-23 19:36:06 -05:00
helper.rb Cleanup tests, parallelize a few (#1850) 2019-07-27 09:47:19 -07:00
test_app_status.rb Test cleanup and parallelization (#1846) 2019-07-16 18:53:28 -04:00
test_binder.rb Test cleanup and parallelization (#1846) 2019-07-16 18:53:28 -04:00
test_cli.rb Instrument start time (#1844) 2019-08-01 12:25:15 -07:00
test_config.rb Cleanup tests, parallelize a few (#1850) 2019-07-27 09:47:19 -07:00
test_events.rb Add REQUEST_PATH on parse error message (#1831) 2019-07-27 09:15:55 -07:00
test_http10.rb make test_helper no longer be loaded as a test (#1283) 2017-05-12 12:16:55 -07:00
test_http11.rb Updates for frozen string literal compatibility. (#1376) 2017-08-02 19:02:40 -06:00
test_integration.rb Fix Typos (#1859) 2019-07-22 10:33:19 -04:00
test_iobuffer.rb make test_helper no longer be loaded as a test (#1283) 2017-05-12 12:16:55 -07:00
test_minissl.rb make test_helper no longer be loaded as a test (#1283) 2017-05-12 12:16:55 -07:00
test_null_io.rb Cleanup tests, parallelize a few (#1850) 2019-07-27 09:47:19 -07:00
test_persistent.rb Cleanup tests, parallelize a few (#1850) 2019-07-27 09:47:19 -07:00
test_puma_server.rb Fix a bug that the last CRLF of chunked body may be used in the next request (#1812) 2019-08-03 15:52:09 -07:00
test_puma_server_ssl.rb Avoid blocking on #read_nonblock 2019-07-30 17:08:44 -04:00
test_pumactl.rb Add status to pumactl with pidfile (#1824) 2019-06-23 19:36:06 -05:00
test_rack_handler.rb Rack handler should use provided default host 2019-01-04 16:09:56 -06:00
test_rack_server.rb Cleanup tests, parallelize a few (#1850) 2019-07-27 09:47:19 -07:00
test_tcp_logger.rb Avoid mutating global STDOUT & STDERR (#1837) 2019-07-25 12:09:51 -07:00
test_tcp_rack.rb Avoid hardcoding ports 2018-03-20 11:25:26 -05:00
test_thread_pool.rb Cleanup tests, parallelize a few (#1850) 2019-07-27 09:47:19 -07:00
test_unix_socket.rb fix test/test_unix_socket.rb (#1870) 2019-07-29 18:16:09 -07:00
test_web_server.rb Cleanup tests, parallelize a few (#1850) 2019-07-27 09:47:19 -07:00