From: James Harton <jamesotron@...>
Date: 2011-10-21T13:05:48+09:00
Subject: [ruby-core:40254] [Ruby 1.9 - Bug #5468][Open] IPSocket#valid_v6? in ipaddr.rb contains incorrect regexps


Issue #5468 has been reported by James Harton.

----------------------------------------
Bug #5468: IPSocket#valid_v6? in ipaddr.rb contains incorrect regexps
http://redmine.ruby-lang.org/issues/5468

Author: James Harton
Status: Open
Priority: Normal
Assignee: 
Category: core
Target version: 1.9.2
ruby -v: ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]


Code to reproduce:

    require 'ipaddr'
    IPAddr.new('FF32:00FF:A12:34FF:FE56:7890::/96', Socket::AF_INET) # See RFC4489

Fails with:

    ArgumentError: invalid address
    	from /Users/jnh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/ipaddr.rb:477:in `rescue in initialize'
    	from /Users/jnh/.rvm/rubies/ruby-1.9.2-p290/lib/ruby/1.9.1/ipaddr.rb:474:in `initialize'
    	from (irb):2:in `new'
    	from (irb):2
    	from /Users/jnh/.rvm/rubies/ruby-1.9.2-p290/bin/irb:16:in `<main>'

I have tested on both 1.9.2 and 1.8.7:

    ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-darwin11.1.0]
    ruby 1.8.7 (2011-06-30 patchlevel 352) [i686-darwin11.2.0]

Looking over #valid_v6 it appears that it contains a number of invalid regular expressions (IPv4 compatible IPv6 addressing was deprecated by RFC4291 in 2006 for example). I would suggest that all the regular expressions are removed and the operating systems inet_pton() call is used to validate it instead.


-- 
http://redmine.ruby-lang.org