Project

General

Profile

Actions

Bug #15832

closed

IPAddr.new accepts invalid mask IP address

Added by tsuna (Kenta Tsuna) almost 5 years ago. Updated over 4 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.7.0dev (2019-05-05 trunk 594a033ff0) [x86_64-linux]
[ruby-core:92567]

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

Updated by jeremyevans0 (Jeremy Evans) almost 5 years ago

  • Status changed from Open to Assigned
  • Assignee set to knu (Akinori MUSHA)

I submitted a pull request to ruby/ipaddr to fix this: https://github.com/ruby/ipaddr/pull/17

Updated by ioquatix (Samuel Williams) over 4 years ago

  • Status changed from Assigned to Closed

I merged it.

Actions

Also available in: Atom PDF

Like0
Like0Like0