1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/resolv/test_addr.rb
nobu cdf1b85ae7 Fixed command Injection
* lib/resolv.rb (Resolv::Config.parse_resolv_conf): fixed
  potential command injection by use of Kernel#open.
  [ruby-core:84347] [Bug #14205]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61351 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2017-12-20 04:25:01 +00:00

41 lines
1 KiB
Ruby

# frozen_string_literal: false
require 'test/unit'
require 'resolv'
require 'socket'
require 'tempfile'
class TestResolvAddr < Test::Unit::TestCase
def test_invalid_ipv4_address
assert_not_match(Resolv::IPv4::Regex, "1.2.3.256", "[ruby-core:29501]")
1000.times {|i|
if i < 256
assert_match(Resolv::IPv4::Regex, "#{i}.#{i}.#{i}.#{i}")
else
assert_not_match(Resolv::IPv4::Regex, "#{i}.#{i}.#{i}.#{i}")
end
}
end
def test_invalid_byte_comment
bug9273 = '[ruby-core:59239] [Bug #9273]'
Tempfile.create('resolv_test_addr_') do |tmpfile|
tmpfile.print("\xff\x00\x40")
tmpfile.close
hosts = Resolv::Hosts.new(tmpfile.path)
assert_nothing_raised(ArgumentError, bug9273) do
hosts.each_address("") {break}
end
end
end
def test_hosts_by_command
Dir.mktmpdir do |dir|
Dir.chdir(dir) do
hosts = Resolv::Hosts.new("|echo error")
assert_raise(Errno::ENOENT) do
hosts.each_name("") {}
end
end
end
end
end