[前][次][番号順一覧][スレッド一覧]

ruby-changes:71377

From: nagachika <ko1@a...>
Date: Sat, 12 Mar 2022 16:54:24 +0900 (JST)
Subject: [ruby-changes:71377] e18e6af604 (ruby_3_0): merge revision(s) 9e0a91d0640600f2dfd7fc1d5fae6667019c9ca5: [Backport #18458]

https://git.ruby-lang.org/ruby.git/commit/?id=e18e6af604

From e18e6af604786be481115c7340c1450332615b57 Mon Sep 17 00:00:00 2001
From: nagachika <nagachika@r...>
Date: Sat, 12 Mar 2022 16:53:37 +0900
Subject: merge revision(s) 9e0a91d0640600f2dfd7fc1d5fae6667019c9ca5: [Backport
 #18458]

	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(-)
---
 error.c                     | 3 ++-
 test/ruby/test_exception.rb | 8 ++++++++
 version.h                   | 2 +-
 3 files changed, 11 insertions(+), 2 deletions(-)

diff --git a/error.c b/error.c
index 73705b0b58..d614a9c0a2 100644
--- a/error.c
+++ b/error.c
@@ -306,7 +306,8 @@ rb_warning_warn(VALUE mod, VALUE str) https://github.com/ruby/ruby/blob/trunk/error.c#L306
 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 087bcda5ac..0f3e11b566 100644
--- a/test/ruby/test_exception.rb
+++ b/test/ruby/test_exception.rb
@@ -1100,6 +1100,14 @@ $stderr = $stdout; raise "\x82\xa0"') do |outs, errs, status| https://github.com/ruby/ruby/blob/trunk/test/ruby/test_exception.rb#L1100
     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;
diff --git a/version.h b/version.h
index 4928ce7c03..f13ae3c33f 100644
--- a/version.h
+++ b/version.h
@@ -12,7 +12,7 @@ https://github.com/ruby/ruby/blob/trunk/version.h#L12
 # define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
 #define RUBY_VERSION_TEENY 4
 #define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 188
+#define RUBY_PATCHLEVEL 189
 
 #define RUBY_RELEASE_YEAR 2022
 #define RUBY_RELEASE_MONTH 3
-- 
cgit v1.2.1


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]