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

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0Like0Like0Like0