Project

General

Profile

Actions

Backport #7477

closed

Certain valid IPv6 Addresses are not recognized as valid

Added by alankessler (Alan Kessler) over 11 years ago. Updated about 11 years ago.

Status:
Closed
[ruby-core:50373]

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 (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

Files

ipaddr.rb.patch (538 Bytes) ipaddr.rb.patch alankessler (Alan Kessler), 11/30/2012 03:29 PM
Actions #1

Updated by usa (Usaku NAKAMURA) over 11 years ago

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

Updated by knu (Akinori MUSHA) about 11 years 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.

Actions #3

Updated by knu (Akinori MUSHA) about 11 years 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]
Actions #4

Updated by knu (Akinori MUSHA) about 11 years ago

  • Tracker changed from Bug to Backport
  • Project changed from Ruby master to Backport200
  • Category deleted (lib)
  • Status changed from Closed to Assigned
  • Assignee changed from knu (Akinori MUSHA) to mame (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.

Actions #5

Updated by knu (Akinori MUSHA) about 11 years ago

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

Actions #6

Updated by mame (Yusuke Endoh) about 11 years ago

  • Assignee changed from mame (Yusuke Endoh) to knu (Akinori MUSHA)

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

--
Yusuke Endoh

Actions #7

Updated by knu (Akinori MUSHA) about 11 years 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]
Actions #8

Updated by knu (Akinori MUSHA) about 11 years ago

  • Project changed from Backport200 to Backport193
  • Status changed from Closed to Assigned
  • Assignee changed from knu (Akinori MUSHA) to usa (Usaku NAKAMURA)
Actions #9

Updated by usa (Usaku NAKAMURA) about 11 years 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.
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0