From bcba9513202d5c799f76f011ab30c6a115db982e Mon Sep 17 00:00:00 2001 From: nobu Date: Thu, 30 Jul 2015 01:42:35 +0000 Subject: load.c: avoid segfault when 'throw' occurs in the middle of rb_load_file_str How can a 'throw' happen while the current thread is reading a Ruby source file from disk and parsing it? It can happen if another thread calls Thread#raise, and passes an Exception object which responds to #exception, and the custom #exception method calls Kernel#throw. In practice, this is most likely to happen if you combine the use of autoload and Timeout.timeout. An extra check is required to avoid a segfault in this case. * load.c (rb_load_internal0): extra check before returning TAG_RAISE when a non-local transfer of control happens while loading and parsing a Ruby source file. [ruby-core:70169] [Bug #11404] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51439 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_require.rb | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_require.rb b/test/ruby/test_require.rb index 7c2a5d3aa8..cf428d1bbe 100644 --- a/test/ruby/test_require.rb +++ b/test/ruby/test_require.rb @@ -706,4 +706,33 @@ class TestRequire < Test::Unit::TestCase END } end unless /mswin|mingw/ =~ RUBY_PLATFORM + + def test_throw_while_loading + Tempfile.create(%w'bug-11404 .rb') do |f| + f.puts 'sleep' + f.close + + assert_separately(["-", f.path], <<-'end;') + path = ARGV[0] + class Error < RuntimeError + def exception(*) + begin + throw :blah + rescue UncaughtThrowError + end + self + end + end + + assert_throw(:blah) do + x = Thread.current + y = Thread.start { + sleep 0.00001 + x.raise Error.new + } + load path + end + end; + end + end end -- cgit v1.2.3