Project

General

Profile

Actions

Bug #18562

closed

throw_data passed to rescue through require

Added by jhawthorn (John Hawthorn) 5 months ago. Updated 3 months ago.

Status:
Closed
Priority:
Normal
Target version:
-
[ruby-core:107403]

Description

When we throw in a require it's incorrectly considered as a raise, making the T_IMEMO throw_data object accessible via rescue (in a contrived case). In regular usage this is unlikely to cause an issue because Module#=== immediately returns false for objects with klass == 0.

With test_throw.rb:

throw :extdep, 42

and

class Anything < Exception
  def self.===(_); true; end
end

catch(:extdep) do
  begin
    require "./test_throw"
  rescue Anything => e
    p e
  end
end

We get

in 'p': method inspect' called on unexpected T_IMEMO object (0x00007f5e1486b130 flags=0x10000301a) (NotImplementedError)

I've proposed a fix via PR https://github.com/ruby/ruby/pull/5513

Actions

Also available in: Atom PDF