Project

General

Profile

Actions

Bug #723

closed

Net::HTTPHeader doesn't check the type of the 'value'

Added by eveel (Dmitry A. Ustalov) about 16 years ago. Updated over 13 years ago.

Status:
Closed
Target version:
-
ruby -v:
[ruby-core:19737]

Description

=begin
initialize_http_header() method of the Net::HTTPHeader doesn't check the type of the 'value', and crashes with exception:
---8<---
/usr/lib/ruby/1.8/net/http.rb:1142:in initialize_http_header': undefined method strip' for 1.43:Float (NoMethodError)
from /usr/lib/ruby/1.8/net/http.rb:1140:in each' from /usr/lib/ruby/1.8/net/http.rb:1140:in initialize_http_header'
from /usr/lib/ruby/1.8/net/http.rb:1472:in initialize' from /usr/lib/ruby/1.8/net/http.rb:1588:in initialize'
from /usr/lib/ruby/1.8/net/http.rb:845:in new' from /usr/lib/ruby/1.8/net/http.rb:845:in post'
--->8---

I think, we need to cast any 'value' to String in the initialize_http_header():
---8<---
def initialize_http_header(initheader)
@header = {}
return unless initheader
initheader.each do |key, value|
warn "net/http: warning: duplicated HTTP header: #{key}" if key?(key) and $VERBOSE
@header[key.downcase] = [value.strip]
end
end
--->8---
Maybe, we should use 'value.to_s.strip' instead of 'value.strip'?

My system is: Fedora 8 i386, ruby 1.8.6 (p111).

// Added later: This bug is also occured in ruby 1.8.6 (2008-08-11 patchlevel 287) [i386-linux] (Fedora 9 i386).
=end


Files

http-rb-fix-crash-when-initializing-header.patch (912 Bytes) http-rb-fix-crash-when-initializing-header.patch not a beautiful, but bugfix eveel (Dmitry A. Ustalov), 11/08/2008 06:41 PM
reproduce.rb (356 Bytes) reproduce.rb reproduce the bug eveel (Dmitry A. Ustalov), 11/08/2008 06:41 PM
Actions #1

Updated by matz (Yukihiro Matsumoto) about 16 years ago

=begin
Hi,

In message "Re: [ruby-core:19737] [Bug #723] Net::HTTPHeader doesn't check the type of the 'value'"
on Sat, 8 Nov 2008 18:39:01 +0900, "Dmitry A. Ustalov" writes:

|Bug #723: Net::HTTPHeader doesn't check the type of the 'value'
|http://redmine.ruby-lang.org/issues/show/723
|
|Author: Dmitry A. Ustalov
|Status: Open, Priority: Normal
|
|initialize_http_header() method of the Net::HTTPHeader doesn't check the type of the 'value', and crashes with exception:
|---8<---
|/usr/lib/ruby/1.8/net/http.rb:1142:in initialize_http_header': |undefined method strip' for 1.43:Float (NoMethodError)

The report lacks the situation info where the error happened, so I
cannot say for sure, but in general, if you pass a float value when
string is required, I think raising error is a sane result. Implicit
conversion often causes more problems than it solves. Is there any
reason that you cannot convert the value to string by yourself?

						matz.

=end

Actions #2

Updated by eveel (Dmitry A. Ustalov) almost 16 years ago

=begin
Hi.

So, you're right. There are no reason where I can't convert
the value to string by myself.

Issue should be closed.
=end

Actions #3

Updated by shyouhei (Shyouhei Urabe) almost 16 years ago

  • Status changed from Open to Closed
  • Assignee set to matz (Yukihiro Matsumoto)

=begin

=end

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0