Issue #15832 has been reported by tsuna (Kenta Tsuna).

----------------------------------------
Bug #15832: IPAddr.new accepts invalid mask IP address
https://bugs.ruby-lang.org/issues/15832

* Author: tsuna (Kenta Tsuna)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: ruby 2.7.0dev (2019-05-05 trunk 594a033ff0) [x86_64-linux]
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN
----------------------------------------
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
```



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request / ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>