ruby-changes:70731
From: Jeremy <ko1@a...>
Date: Wed, 5 Jan 2022 03:03:34 +0900 (JST)
Subject: [ruby-changes:70731] 9e0a91d064 (master): Don't segfault if Warning.warn is undefined
https://git.ruby-lang.org/ruby.git/commit/?id=9e0a91d064 From 9e0a91d0640600f2dfd7fc1d5fae6667019c9ca5 Mon Sep 17 00:00:00 2001 From: Jeremy Evans <code@j...> Date: Tue, 4 Jan 2022 09:13:19 -0800 Subject: 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] --- error.c | 3 ++- test/ruby/test_exception.rb | 8 ++++++++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/error.c b/error.c index 6a60919d5c7..c7c5159927f 100644 --- a/error.c +++ b/error.c @@ -317,7 +317,8 @@ rb_warning_warn(VALUE mod, VALUE str) https://github.com/ruby/ruby/blob/trunk/error.c#L317 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 diff --git a/test/ruby/test_exception.rb b/test/ruby/test_exception.rb index 2985f75fd60..3be9b9aee0e 100644 --- a/test/ruby/test_exception.rb +++ b/test/ruby/test_exception.rb @@ -1192,6 +1192,14 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1192 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; -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/