Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IPAddr.new accepts certain IPv6 literals when AF_INET is specified #62

Open
hanazuki opened this issue Nov 28, 2023 · 0 comments
Open

Comments

@hanazuki
Copy link
Contributor

If the given address is an IPv6 literal enclosed in brackets and/or with a zone ID suffix, it will be unexpectedly accepted.
All the following invocations expect AddressFamilyError.

% bundle exec irb -ripaddr
irb(main):001:0> IPAddr.new('[::]', Socket::AF_INET)
=> #<IPAddr: IPv6:0000:0000:0000:0000:0000:0000:0000:0000/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
irb(main):002:0> IPAddr.new('::%eth0', Socket::AF_INET)
=> #<IPAddr: IPv6:0000:0000:0000:0000:0000:0000:0000:0000%eth0/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
irb(main):003:0> IPAddr.new('[::%eth0]', Socket::AF_INET)
=> #<IPAddr: IPv6:0000:0000:0000:0000:0000:0000:0000:0000%eth0/ffff:ffff:ffff:ffff:ffff:ffff:ffff:ffff>
irb(main):004:0> IPAddr.new('::', Socket::AF_INET)
/.../ruby/ipaddr/lib/ipaddr.rb:633:in `initialize': address family mismatch (IPAddr::AddressFamilyError)
      raise AddressFamilyError, "address family mismatch"
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

1 participant