[ruby-trunk - Bug #8054][Open] open-uri と resolv-replace を同時にロードすると壊れる

Issue #8054 has been reported by mrkn (Kenta M.).


Bug #8054: open-uri と resolv-replace を同時にロードすると壊れる
https://bugs.ruby-lang.org/issues/8054

Author: mrkn (Kenta M.)
Status: Open
Priority: Normal
Assignee: akr (Akira T.)
Category: lib
Target version:
ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]

以下のように、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) [x86_64-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:ingenerate_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:ineach_resource’
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:inblock 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:ineach_address’
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:ingetaddress’
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:ininitialize’
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:inblock 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:inconnect’
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:instart’
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:inbuffer_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:incatch’
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:inopen_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:inopen’
from -e:1:in `’

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

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

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 original_resolv_initialize initialize

:startdoc:

  • def initialize(host, serv, *rest)
  • rest[0] = IPSocket.getaddress(rest[0]) unless rest.empty?
  • original_resolv_initialize(IPSocket.getaddress(host), serv, *rest)
  • def initialize(host, serv, local_host=nil, local_serv=nil)
  • local_host = IPSocket.getaddress(local_host) if local_host
  • original_resolv_initialize(IPSocket.getaddress(host), serv,
    local_host, local_serv)
    end
    end

Bug #8054: open-uri と resolv-replace を同時にロードすると壊れる
https://bugs.ruby-lang.org/issues/8054#change-37478

Author: mrkn (Kenta M.)
Status: Open
Priority: Normal
Assignee: akr (Akira T.)
Category: lib
Target version:
ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]

以下のように、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) [x86_64-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:ingenerate_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:ineach_resource’
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:inblock 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:ineach_address’
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:ingetaddress’
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:ininitialize’
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:inblock 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:inconnect’
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:instart’
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:inbuffer_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:incatch’
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:inopen_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:inopen’
from -e:1:in `’

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

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

Bug #8054: open-uri と resolv-replace を同時にロードすると壊れる
https://bugs.ruby-lang.org/issues/8054#change-37496

Author: mrkn (Kenta M.)
Status: Open
Priority: Normal
Assignee: akr (Akira T.)
Category: lib
Target version:
ruby -v: ruby 2.0.0p0 (2013-02-24 revision 39474) [x86_64-darwin12.2.0]

以下のように、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) [x86_64-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:ingenerate_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:ineach_resource’
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:inblock 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:ineach_address’
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:ingetaddress’
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:ininitialize’
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:inblock 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:inconnect’
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:instart’
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:inbuffer_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:incatch’
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:inopen_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:inopen’
from -e:1:in `’

2013/3/11 mrkn (Kenta M.) [email protected]:

@@ -18,9 +18,9 @@ class TCPSocket < IPSocket
end
$B0z?t$N?t$rJQ$($k$N$b$J$s$J$N$G!"(Br39725 $B$H$$$&46$8$G!#(B

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs