Project

General

Profile

Bug #15832

IPAddr.new accepts invalid mask IP address

Added by tsuna (Kenta Tsuna) 4 months ago. Updated about 1 month ago.

Status:
Closed
Priority:
Normal
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

History

Updated by jeremyevans0 (Jeremy Evans) 3 months ago

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

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

Updated by ioquatix (Samuel Williams) about 1 month ago

  • Status changed from Assigned to Closed

I merged it.

Also available in: Atom PDF