Project

General

Profile

Actions

Bug #13399

closed

IPAddr accepts invalid address mask

Added by rtib (Tibor Repasi) about 7 years ago. Updated over 6 years ago.

Status:
Closed
Target version:
-
ruby -v:
ruby 2.4.1p111 (2017-03-22 revision 58053) [x86_64-darwin15]
[ruby-core:80556]

Description

API Class IPAddr can be initialised with e.g. '1.2.3.4/255.255.255.1', which is an invalid mask for an IPv4 address, however, IPAddr.new won't throw ArgumentError, nor ip.ipv4? will return false.

$ cat iptest.rb
require 'ipaddr'

begin
  ip = IPAddr.new('1.2.3.4/255.255.255.1')
rescue ArgumentError
  puts 'ArgumentError was thrown'
end
puts 'IP address is valid' if ip.ipv4?
$ ruby iptest.rb
IP address is valid
$ ipcalc 1.2.3.4/255.255.255.1
INVALID NETMASK
INVALID MASK1:   255.255.255.1

Address:   1.2.3.4              00000001.00000010.00000011. 00000100
Netmask:   255.255.255.0 = 24   11111111.11111111.11111111. 00000000
Wildcard:  0.0.0.255            00000000.00000000.00000000. 11111111
=>
Network:   1.2.3.0/24           00000001.00000010.00000011. 00000000
HostMin:   1.2.3.1              00000001.00000010.00000011. 00000001
HostMax:   1.2.3.254            00000001.00000010.00000011. 11111110
Broadcast: 1.2.3.255            00000001.00000010.00000011. 11111111
Hosts/Net: 254                   Class A

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0