Repository navigation
Conversation
"::" stands for one or more groups of zeros, so a compressed address can have at most 7 other groups (5 before an embedded IPv4 address). IPv6::Regex did not count the groups: * "1:2:3:4:5:6:7:8::" matched and IPv6.create silently dropped the "::", returning 1:2:3:4:5:6:7:8. * "1:2:3:4:5:6:7:8:9::" and "1:2:3:4:5:6:7::1.2.3.4" matched, but IPv6.create failed with "negative argument" from String#*. Resolv.getaddress returned such strings as addresses without a lookup, and Resolv::DNS#getname raised the "negative argument" ArgumentError. Add a lookahead to Regex_CompressedHex and Regex_CompressedHex4Dec that rejects too many groups.
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
::stands for one or more groups of zeros (RFC 4291 2.2), so a compressed address can have at most 7 other groups, or 5 before an embedded IPv4 address.IPv6::Regexdid not count the groups:The "negative argument" comes from
"\0" * omitlenwhen the groups already fill more than 16 bytes. BecauseResolv::AddressRegexalso matched,Resolv.getaddress("1:2:3:4:5:6:7:8:9::")returned the string as an address without a lookup, andResolv::DNS.new.getnameraised theArgumentError.This adds a lookahead to
Regex_CompressedHexandRegex_CompressedHex4Decthat rejects too many groups, so these strings no longer match andIPv6.createraises the usual "not numeric IPv6 address" error.The new test fails without the change.
rake testpasses. I also comparedIPv6::Regex+IPv6.createagainst Python'sipaddresson about 19k random addresses: after this change the only remaining difference is an embedded IPv4 part with an octet over 255 (like::1.2.3.256), which the regex still matches butcreatealready rejects with the normal error. I left that alone.