Backport #8054

open-uri と resolv-replace を同時にロードすると壊れる

Added by Kenta Murata about 1 year ago. Updated about 1 year ago.

[ruby-dev:47150]
Status:Closed
Priority:Normal
Assignee:Tomoyuki Chikanaga

Description

以下のように、open-uri と resolv-replace を同時にロードすると壊れます。

$ ruby -ropen-uri -rresolv-replace -ve 'open("http://www.ruby-lang.org/")'
ruby 2.0.0p0 (2013-02-24 revision 39474) [x8664-darwin12.2.0]
/Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/resolv.rb:1176:in create': cannot interpret as DNS name: nil (ArgumentError)
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/resolv.rb:1022:in
generate
candidates'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/resolv.rb:1047:in resolv'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/resolv.rb:513:in
eachresource'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/resolv.rb:406:in each_address'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/resolv.rb:115:in
block in each
address'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/resolv.rb:114:in each'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/resolv.rb:114:in
eachaddress'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/resolv.rb:92:in getaddress'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/resolv.rb:43:in
getaddress'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/resolv-replace.rb:10:in getaddress'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/resolv-replace.rb:22:in
initialize'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/net/http.rb:877:in open'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/net/http.rb:877:in
block in connect'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/timeout.rb:51:in timeout'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/net/http.rb:876:in
connect'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/net/http.rb:861:in do_start'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/net/http.rb:850:in
start'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/open-uri.rb:313:in open_http'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/open-uri.rb:708:in
buffer
open'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/open-uri.rb:210:in block in open_loop'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/open-uri.rb:208:in
catch'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/open-uri.rb:208:in open_loop'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/open-uri.rb:149:in
open_uri'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/open-uri.rb:688:in open'
from /Users/kenta-murata/.rbenv/versions/2.0.0-p0/lib/ruby/2.0.0/open-uri.rb:34:in
open'
from -e:1:in `'


Related issues

Related to ruby-trunk - Bug #8113: ArgumentError: cannot interpret as DNS name: nil Closed 03/18/2013

Associated revisions

Revision 40089
Added by Tomoyuki Chikanaga about 1 year ago

merge revision(s) 39725: [Backport #8054]

* lib/resolv-replace.rb (TCPSocket#initialize): resolve the 3rd
  argument only if non-nil value is given.
   [ruby-trunk - Bug #8054] reported and analyzed by
  mrkn.

History

#1 Updated by Kenta Murata about 1 year ago

以下のような修正で正しく動いてるようです:

diff --git a/lib/resolv-replace.rb b/lib/resolv-replace.rb
index ff34f90..374c81a 100644
--- a/lib/resolv-replace.rb
+++ b/lib/resolv-replace.rb
@@ -18,9 +18,9 @@ class TCPSocket < IPSocket
# :stopdoc:
alias originalresolvinitialize initialize
# :startdoc:
- def initialize(host, serv, *rest)
- rest[0] = IPSocket.getaddress(rest[0]) unless rest.empty?
- originalresolvinitialize(IPSocket.getaddress(host), serv, *rest)
+ def initialize(host, serv, localhost=nil, localserv=nil)
+ localhost = IPSocket.getaddress(localhost) if localhost
+ original
resolvinitialize(IPSocket.getaddress(host), serv, localhost, local_serv)
end
end

#2 Updated by Kenta Murata about 1 year ago

この問題が起きるようになったのは r36367 の変更からだと思います。
r36367 より、Net::HTTP#connect で、TCPSocket.open の第3引数と第4引数が
必ず明示的に渡されるようになりました。
この変更に対して resolv-replace.rb が追従していません。
resolv-replace のテスト無かったから気づかなかったんでしょうね。

#3 Updated by Akira Tanaka about 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r39725.
Kenta, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • lib/resolv-replace.rb (TCPSocket#initialize): resolve the 3rd argument only if non-nil value is given. [ruby-trunk - Bug #8054] reported and analyzed by mrkn.

#4 Updated by Akira Tanaka about 1 year ago

2013/3/11 mrkn (Kenta Murata) muraken@gmail.com:

Issue #8054 has been updated by mrkn (Kenta Murata).

以下のような修正で正しく動いてるようです:

diff --git a/lib/resolv-replace.rb b/lib/resolv-replace.rb
index ff34f90..374c81a 100644
--- a/lib/resolv-replace.rb
+++ b/lib/resolv-replace.rb
@@ -18,9 +18,9 @@ class TCPSocket < IPSocket
# :stopdoc:
alias originalresolvinitialize initialize
# :startdoc:
- def initialize(host, serv, *rest)
- rest[0] = IPSocket.getaddress(rest[0]) unless rest.empty?
- originalresolvinitialize(IPSocket.getaddress(host), serv, *rest)
+ def initialize(host, serv, localhost=nil, localserv=nil)
+ localhost = IPSocket.getaddress(localhost) if localhost
+ original
resolvinitialize(IPSocket.getaddress(host), serv, localhost, local_serv)
end
end

引数の数を変えるのもなんなので、r39725 という感じで。
--
[田中 哲][たなか あきら][Tanaka Akira]

#5 Updated by Tomoyuki Chikanaga about 1 year ago

  • Tracker changed from Bug to Backport
  • Project changed from ruby-trunk to Backport200
  • Category deleted (lib)
  • Status changed from Closed to Assigned
  • Assignee changed from Akira Tanaka to Tomoyuki Chikanaga

#6 Updated by Tomoyuki Chikanaga about 1 year ago

  • Status changed from Assigned to Closed

This issue was solved with changeset r40089.
Kenta, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 39725: [Backport #8054]

* lib/resolv-replace.rb (TCPSocket#initialize): resolve the 3rd
  argument only if non-nil value is given.
   [ruby-trunk - Bug #8054] reported and analyzed by
  mrkn.

Also available in: Atom PDF