1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

Don't segfault if Warning.warn is undefined

Check that there is a method entry for the method before passing
it to rb_method_entry_arity.

Fixes [Bug #18458]
This commit is contained in:
Jeremy Evans 2022-01-04 09:13:19 -08:00
parent e7806049c0
commit 9e0a91d064
Notes: git 2022-01-05 03:03:40 +09:00
2 changed files with 10 additions and 1 deletions

View file

@ -317,7 +317,8 @@ rb_warning_warn(VALUE mod, VALUE str)
static int
rb_warning_warn_arity(void)
{
return rb_method_entry_arity(rb_method_entry(rb_singleton_class(rb_mWarning), id_warn));
const rb_method_entry_t *me = rb_method_entry(rb_singleton_class(rb_mWarning), id_warn);
return me ? rb_method_entry_arity(me) : 1;
}
static VALUE

View file

@ -1192,6 +1192,14 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status|
assert_empty warning
end
def test_undef_Warning_warn
assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
begin;
Warning.undef_method(:warn)
assert_raise(NoMethodError) { warn "" }
end;
end
def test_undefined_backtrace
assert_separately([], "#{<<-"begin;"}\n#{<<-"end;"}")
begin;