Backport #7477
closedCertain valid IPv6 Addresses are not recognized as valid
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 = ""
-
elseaddr = 0 end
Files
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.
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]
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.
Updated by knu (Akinori MUSHA) about 11 years ago
Sorry, r39299 contained a typo, which was fixed in r39300.
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 mame@tsg.ne.jp
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]
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)
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.