Actions
Bug #15832
closedIPAddr.new accepts invalid mask IP address
Description
IPAddr.new accepts IP address with multiple mask and/or zero padded one.
$ cat ipaddr.rb
require 'ipaddr'
addrs = %w[192.0.2.0/24/16
192.0.2.0/00024
192.0.2.0/24/00016
192.0.2.0/00024/16
2001:db8::/32/24
2001:db8::/00032
2001:db8::/32/00024
2001:db8::/00032/24]
addrs.each do |addr|
begin
p IPAddr.new(addr)
puts "#{addr} is valid"
rescue StandardError
puts "#{addr} is invalid"
end
end
$ ruby ipaddr.rb
#<IPAddr: IPv4:192.0.2.0/255.255.255.0>
192.0.2.0/24/16 is valid
#<IPAddr: IPv4:192.0.2.0/255.255.255.0>
192.0.2.0/00024 is valid
#<IPAddr: IPv4:192.0.2.0/255.255.255.0>
192.0.2.0/24/00016 is valid
#<IPAddr: IPv4:192.0.2.0/255.255.255.0>
192.0.2.0/00024/16 is valid
#<IPAddr: IPv6:2001:0db8:0000:0000:0000:0000:0000:0000/ffff:ffff:0000:0000:0000:0000:0000:0000>
2001:db8::/32/24 is valid
#<IPAddr: IPv6:2001:0db8:0000:0000:0000:0000:0000:0000/ffff:ffff:0000:0000:0000:0000:0000:0000>
2001:db8::/00032 is valid
#<IPAddr: IPv6:2001:0db8:0000:0000:0000:0000:0000:0000/ffff:ffff:0000:0000:0000:0000:0000:0000>
2001:db8::/32/00024 is valid
#<IPAddr: IPv6:2001:0db8:0000:0000:0000:0000:0000:0000/ffff:ffff:0000:0000:0000:0000:0000:0000>
2001:db8::/00032/24 is valid
Actions
Like0
Like0Like0