* lib/webrick/httprequest.rb, lib/webrick/cgi.rb: Request-Line or
header fields shold be read with maximum length. [ruby-talk:231745] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@14260 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3f07e548fc
commit
1e8c6e2ba4
@ -1,3 +1,8 @@
|
|||||||
|
Mon Dec 17 16:02:30 2007 GOTOU Yuuzou <gotoyuzo@notwork.org>
|
||||||
|
|
||||||
|
* lib/webrick/httprequest.rb, lib/webrick/cgi.rb: Request-Line or
|
||||||
|
header fields shold be read with maximum length. [ruby-talk:231745]
|
||||||
|
|
||||||
Mon Dec 17 14:03:39 2007 Tanaka Akira <akr@fsij.org>
|
Mon Dec 17 14:03:39 2007 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* include/ruby/encoding.h (ENC_CODERANGE_VALID): rename from
|
* include/ruby/encoding.h (ENC_CODERANGE_VALID): rename from
|
||||||
|
@ -196,8 +196,8 @@ module WEBrick
|
|||||||
[nil, @server_port, @server_name, @server_addr]
|
[nil, @server_port, @server_name, @server_addr]
|
||||||
end
|
end
|
||||||
|
|
||||||
def gets(eol=LF)
|
def gets(eol=LF, size=nil)
|
||||||
input.gets(eol)
|
input.gets(eol, size)
|
||||||
end
|
end
|
||||||
|
|
||||||
def read(size=nil)
|
def read(size=nil)
|
||||||
|
@ -219,7 +219,10 @@ module WEBrick
|
|||||||
private
|
private
|
||||||
|
|
||||||
def read_request_line(socket)
|
def read_request_line(socket)
|
||||||
@request_line = read_line(socket) if socket
|
@request_line = read_line(socket, 1024) if socket
|
||||||
|
if @request_line.size >= 1024 and @request_line[-1, 1] != LF
|
||||||
|
raise HTTPStatus::RequestURITooLarge
|
||||||
|
end
|
||||||
@request_time = Time.now
|
@request_time = Time.now
|
||||||
raise HTTPStatus::EOFError unless @request_line
|
raise HTTPStatus::EOFError unless @request_line
|
||||||
if /^(\S+)\s+(\S+)(?:\s+HTTP\/(\d+\.\d+))?\r?\n/mo =~ @request_line
|
if /^(\S+)\s+(\S+)(?:\s+HTTP\/(\d+\.\d+))?\r?\n/mo =~ @request_line
|
||||||
@ -317,10 +320,10 @@ module WEBrick
|
|||||||
@remaining_size = 0
|
@remaining_size = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
def _read_data(io, method, arg)
|
def _read_data(io, method, *arg)
|
||||||
begin
|
begin
|
||||||
WEBrick::Utils.timeout(@config[:RequestTimeout]){
|
WEBrick::Utils.timeout(@config[:RequestTimeout]){
|
||||||
return io.__send__(method, arg)
|
return io.__send__(method, *arg)
|
||||||
}
|
}
|
||||||
rescue Errno::ECONNRESET
|
rescue Errno::ECONNRESET
|
||||||
return nil
|
return nil
|
||||||
@ -329,8 +332,8 @@ module WEBrick
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_line(io)
|
def read_line(io, size=4096)
|
||||||
_read_data(io, :gets, LF)
|
_read_data(io, :gets, LF, size)
|
||||||
end
|
end
|
||||||
|
|
||||||
def read_data(io, size)
|
def read_data(io, size)
|
||||||
|
@ -56,6 +56,16 @@ class TestWEBrickHTTPRequest < Test::Unit::TestCase
|
|||||||
assert(req.query.empty?)
|
assert(req.query.empty?)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def test_request_uri_too_large
|
||||||
|
msg = <<-_end_of_message_
|
||||||
|
GET /#{"a"*1024} HTTP/1.1
|
||||||
|
_end_of_message_
|
||||||
|
req = WEBrick::HTTPRequest.new(WEBrick::Config::HTTP)
|
||||||
|
assert_raises(WEBrick::HTTPStatus::RequestURITooLarge){
|
||||||
|
req.parse(StringIO.new(msg.gsub(/^ {6}/, "")))
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
def test_parse_headers
|
def test_parse_headers
|
||||||
msg = <<-_end_of_message_
|
msg = <<-_end_of_message_
|
||||||
GET /path HTTP/1.1
|
GET /path HTTP/1.1
|
||||||
|
Loading…
x
Reference in New Issue
Block a user