Forum: Ruby-core [ruby-trunk - Bug #7477][Open] Certain valid IPv6 Addresses are not recognized as valid

Posted by alankessler (Alan Kessler) (Guest)
on 2012-11-30 07:29
(Received via mailing list)
Issue #7477 has been reported by alankessler (Alan Kessler).

----------------------------------------
Bug #7477: Certain valid IPv6 Addresses are not recognized as valid
https://bugs.ruby-lang.org/issues/7477

Author: alankessler (Alan Kessler)
Status: Open
Priority: Normal
Assignee:
Category:
Target version:
ruby -v: 1.9.3p327


IPv6 addresses of the format:

::2:3:4:5:6:7:8
and
2:3:4:5:6:7:8::

improperly raise an InvalidAddressError

This is because this line 
(https://github.com/ruby/ruby/blob/trunk/lib/ipaddr.rb#L552) ignores the 
edge cases where there are 8 colons but the IPv6 still matches the 
compressed format (RE_IPV6ADDRLIKE_COMPRESSED).

the following patch will resolve this bug.

--- ipaddr.rb  2012-11-29 22:11:05.000000000 -0800
+++ ipaddrpatch.rb  2012-11-29 22:07:30.000000000 -0800
@@ -548,11 +548,15 @@
         addr = in_addr($~[4,4])
         left = $1
         right = $3 + '0:0'
-      else
+      elsif !($1 == "" or $2 == "")
         left.count(':') <= 7 or raise InvalidAddressError, "invalid 
address"
         left = $1
         right = $2
         addr = 0
+      else
+        left = $1 + $2
+        right = ""
+        addr = 0
       end
     else
Posted by knu (Akinori MUSHA) (Guest)
on 2013-02-18 04:34
(Received via mailing list)
Issue #7477 has been updated by knu (Akinori MUSHA).


Thanks for the catch!

Your fix doesn't seem quite right when the left part is empty, so I'll 
make a correct fix shortly with some tests.
----------------------------------------
Bug #7477: Certain valid IPv6 Addresses are not recognized as valid
https://bugs.ruby-lang.org/issues/7477#change-36486

Author: alankessler (Alan Kessler)
Status: Assigned
Priority: Normal
Assignee: knu (Akinori MUSHA)
Category: lib
Target version: 2.0.0
ruby -v: 1.9.3p327


IPv6 addresses of the format:

::2:3:4:5:6:7:8
and
2:3:4:5:6:7:8::

improperly raise an InvalidAddressError

This is because this line 
(https://github.com/ruby/ruby/blob/trunk/lib/ipaddr.rb#L552) ignores the 
edge cases where there are 8 colons but the IPv6 still matches the 
compressed format (RE_IPV6ADDRLIKE_COMPRESSED).

the following patch will resolve this bug.

--- ipaddr.rb  2012-11-29 22:11:05.000000000 -0800
+++ ipaddrpatch.rb  2012-11-29 22:07:30.000000000 -0800
@@ -548,11 +548,15 @@
         addr = in_addr($~[4,4])
         left = $1
         right = $3 + '0:0'
-      else
+      elsif !($1 == "" or $2 == "")
         left.count(':') <= 7 or raise InvalidAddressError, "invalid 
address"
         left = $1
         right = $2
         addr = 0
+      else
+        left = $1 + $2
+        right = ""
+        addr = 0
       end
     else
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.