From 38da84296c0e50c4285d8a8c146af5fc3c8afc7d Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 7 May 2019 08:39:42 +0900 Subject: [PATCH] [ruby/ipaddr] Raise if extra slashes follow https://bugs.ruby-lang.org/issues/15832 https://github.com/ruby/ipaddr/commit/de9805d6fa --- lib/ipaddr.rb | 2 +- test/test_ipaddr.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/ipaddr.rb b/lib/ipaddr.rb index 26d1bd7409..6385d69c6a 100644 --- a/lib/ipaddr.rb +++ b/lib/ipaddr.rb @@ -566,7 +566,7 @@ class IPAddr raise AddressFamilyError, "unsupported address family: #{family}" end end - prefix, prefixlen = addr.split('/') + prefix, prefixlen = addr.split('/', 2) if prefix =~ /\A\[(.*)\]\z/i prefix = $1 family = Socket::AF_INET6 diff --git a/test/test_ipaddr.rb b/test/test_ipaddr.rb index e2243dc542..3c3d70e3f2 100644 --- a/test/test_ipaddr.rb +++ b/test/test_ipaddr.rb @@ -91,6 +91,7 @@ class TC_IPAddr < Test::Unit::TestCase assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("[192.168.1.2]/120") } assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("[2001:200:300::]\nINVALID") } assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.1/32\nINVALID") } + assert_raise(IPAddr::InvalidAddressError) { IPAddr.new("192.168.0.1/32/20") } assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("::1/255.255.255.0") } assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("::1/129") } assert_raise(IPAddr::InvalidPrefixError) { IPAddr.new("192.168.0.1/33") }