Backport #7477

Certain valid IPv6 Addresses are not recognized as valid

Added by Alan Kessler over 1 year ago. Updated about 1 year ago.

[ruby-core:50373]
Status:Closed
Priority:Normal
Assignee:Usaku NAKAMURA

Description

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 (REIPV6ADDRLIKECOMPRESSED).

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

ipaddr.rb.patch Magnifier (538 Bytes) Alan Kessler, 11/30/2012 03:29 PM

Associated revisions

Revision 40230
Added by Usaku NAKAMURA about 1 year ago

merge revision(s) 39299,39300: [Backport #7477]

* lib/ipaddr.rb (IPAddr#in6_addr): Fix the parser so that it can
  recognize IPv6 addresses with only one edge 16-bit piece
  compressed, like [::2:3:4:5:6:7:8] or [1:2:3:4:5:6:7::].
  [Bug #7477]

* lib/ipaddr.rb (IPAddr#in6_addr): Fix a typo with the closing
  parenthesis.

History

#1 Updated by Usaku NAKAMURA over 1 year ago

  • Category set to lib
  • Status changed from Open to Assigned
  • Assignee set to Akinori MUSHA
  • Target version set to 2.0.0

#2 Updated by Akinori MUSHA about 1 year ago

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.

#3 Updated by Akinori MUSHA about 1 year ago

  • Status changed from Assigned to Closed

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


Fix the IPv6 parser.

  • lib/ipaddr.rb (IPAddr#in6_addr): Fix the parser so that it can recognize IPv6 addresses with only one edge 16-bit piece compressed, like [::2:3:4:5:6:7:8] or [1:2:3:4:5:6:7::]. [Bug #7477]

#4 Updated by Akinori MUSHA 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 Akinori MUSHA to Yusuke Endoh
  • Target version deleted (2.0.0)

This bug has been there in 1.9 since 1.9.3 2012-06-05 and we never saw a bug report until after half an year, so this may not be a showstopper for everyone, but this is still an important fix for the users of IPAddr, and it's simple.

In any case, please pass this backport request to Backport93 when you're done with it, thanks.

#5 Updated by Akinori MUSHA about 1 year ago

Sorry, r39299 contained a typo, which was fixed in r39300.

#6 Updated by Yusuke Endoh about 1 year ago

  • Assignee changed from Yusuke Endoh to Akinori MUSHA

Knu-san, I believe you. Please backport both r39299 and r39300. Thank you in advance!

Yusuke Endoh mame@tsg.ne.jp

#7 Updated by Akinori MUSHA about 1 year ago

  • Status changed from Assigned to Closed

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


merge revision(s) 39298:39300:

* lib/ipaddr.rb (IPAddr#in6_addr): Fix a typo with the closing
  parenthesis.

* lib/ipaddr.rb (IPAddr#in6_addr): Fix the parser so that it can
  recognize IPv6 addresses with only one edge 16-bit piece
  compressed, like [::2:3:4:5:6:7:8] or [1:2:3:4:5:6:7::].
  [Bug #7477]

#8 Updated by Akinori MUSHA about 1 year ago

  • Project changed from Backport200 to Backport93
  • Status changed from Closed to Assigned
  • Assignee changed from Akinori MUSHA to Usaku NAKAMURA

#9 Updated by Usaku NAKAMURA about 1 year ago

  • Status changed from Assigned to Closed

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


merge revision(s) 39299,39300: [Backport #7477]

* lib/ipaddr.rb (IPAddr#in6_addr): Fix the parser so that it can
  recognize IPv6 addresses with only one edge 16-bit piece
  compressed, like [::2:3:4:5:6:7:8] or [1:2:3:4:5:6:7::].
  [Bug #7477]

* lib/ipaddr.rb (IPAddr#in6_addr): Fix a typo with the closing
  parenthesis.

Also available in: Atom PDF