From d503381ce8ac41d91c195313ea1da5f67ba8250c Mon Sep 17 00:00:00 2001 From: nobu Date: Tue, 26 Nov 2013 13:43:40 +0000 Subject: hash.c: cut off if recursion * hash.c (rb_hash): cut off if recursion detected to get rid of stack overflow. [ruby-core:58567] [Bug #9151] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43859 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_hash.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index c8cf5c6fbf..5f72dec5f4 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -1060,6 +1060,20 @@ class TestHash < Test::Unit::TestCase end end + def test_recursive_hash_value + bug9151 = '[ruby-core:58567] [Bug #9151]' + + s = Struct.new(:x) {def hash; [x,""].hash; end} + a = s.new + b = s.new + a.x = b + b.x = a + ah = assert_nothing_raised(SystemStackError, bug9151) {a.hash} + bh = assert_nothing_raised(SystemStackError, bug9151) {b.hash} + assert_equal(ah, bh, bug9151) + assert_not_equal([a,"hello"].hash, [b,"world"].hash, bug9151) + end + class TestSubHash < TestHash class SubHash < Hash end -- cgit v1.2.3