ruby-changes:52611
From: normal <ko1@a...>
Date: Mon, 24 Sep 2018 16:48:37 +0900 (JST)
Subject: [ruby-changes:52611] normal:r64823 (trunk): webrick: raise EOFError in parse when read line is nil
normal 2018-09-24 16:48:33 +0900 (Mon, 24 Sep 2018) New Revision: 64823 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=64823 Log: webrick: raise EOFError in parse when read line is nil [Bug #15146] From: Justin Li <git@j...> Modified files: trunk/lib/webrick/httprequest.rb trunk/test/webrick/test_httprequest.rb Index: test/webrick/test_httprequest.rb =================================================================== --- test/webrick/test_httprequest.rb (revision 64822) +++ test/webrick/test_httprequest.rb (revision 64823) @@ -422,4 +422,11 @@ GET / https://github.com/ruby/ruby/blob/trunk/test/webrick/test_httprequest.rb#L422 req.body } end + + def test_eof_raised_when_line_is_nil + assert_raise(WEBrick::HTTPStatus::EOFError) { + req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP) + req.parse(StringIO.new("")) + } + end end Index: lib/webrick/httprequest.rb =================================================================== --- lib/webrick/httprequest.rb (revision 64822) +++ lib/webrick/httprequest.rb (revision 64823) @@ -445,12 +445,14 @@ module WEBrick https://github.com/ruby/ruby/blob/trunk/lib/webrick/httprequest.rb#L445 def read_request_line(socket) @request_line = read_line(socket, MAX_URI_LENGTH) if socket + raise HTTPStatus::EOFError unless @request_line + @request_bytes = @request_line.bytesize if @request_bytes >= MAX_URI_LENGTH and @request_line[-1, 1] != LF raise HTTPStatus::RequestURITooLarge end + @request_time = Time.now - raise HTTPStatus::EOFError unless @request_line if /^(\S+)\s+(\S++)(?:\s+HTTP\/(\d+\.\d+))?\r?\n/mo =~ @request_line @request_method = $1 @unparsed_uri = $2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/