From 149d43d4ad1e5a65e3c8601bf3323e09e2e540f4 Mon Sep 17 00:00:00 2001 From: normal Date: Tue, 28 Mar 2017 17:14:49 +0000 Subject: [PATCH] test/ruby/test_symbol.rb: new test for nondeterminism We need to ensure hashes for static symbols remain non-deterministic to avoid DoS attacks. This is currently the case since 2.4+, but was not for the 2.3 series. * test/ruby/test_symbol.rb (test_hash_nondeterministic): new test [ruby-core:80430] [Bug #13376] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58200 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_symbol.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/test/ruby/test_symbol.rb b/test/ruby/test_symbol.rb index 42b5106298..39b2c7692a 100644 --- a/test/ruby/test_symbol.rb +++ b/test/ruby/test_symbol.rb @@ -500,4 +500,14 @@ class TestSymbol < Test::Unit::TestCase assert_equal str, str.to_sym.to_s assert_not_predicate(str, :frozen?, bug11721) end + + def test_hash_nondeterministic + ruby = EnvUtil.rubybin + refute_equal `#{ruby} -e 'puts :foo.hash'`, `#{ruby} -e 'puts :foo.hash'`, + '[ruby-core:80430] [Bug #13376]' + + sym = "dynsym_#{Random.rand(10000)}_#{Time.now}" + refute_equal `#{ruby} -e 'puts #{sym.inspect}.to_sym.hash'`, + `#{ruby} -e 'puts #{sym.inspect}.to_sym.hash'` + end end