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

ruby-changes:61452

From: Nobuyoshi <ko1@a...>
Date: Tue, 2 Jun 2020 19:06:33 +0900 (JST)
Subject: [ruby-changes:61452] d05f04d27d (master): Fixed `defined?` against protected method call

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

From d05f04d27dd86c67e4a8dfff4392f806cf577bdf Mon Sep 17 00:00:00 2001
From: Nobuyoshi Nakada <nobu@r...>
Date: Tue, 2 Jun 2020 18:55:06 +0900
Subject: Fixed `defined?` against protected method call

Protected methods are restricted to be called according to the
class/module in where it is defined, not the actual receiver's
class.  [Bug #16931]

diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb
index 387472a..e1571d5 100644
--- a/test/ruby/test_defined.rb
+++ b/test/ruby/test_defined.rb
@@ -59,6 +59,7 @@ class TestDefined < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_defined.rb#L59
     f = Foo.new
     assert_nil(defined?(f.foo))         # protected method
     f.bar(f) { |v| assert(v) }
+    f.bar(Class.new(Foo).new) { |v| assert(v, "inherited protected method") }
   end
 
   def test_defined_undefined_method
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index f6e3795..9494b8b 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -3603,7 +3603,7 @@ vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_ https://github.com/ruby/ruby/blob/trunk/vm_insnhelper.c#L3603
 	      case METHOD_VISI_PRIVATE:
 		break;
 	      case METHOD_VISI_PROTECTED:
-		if (!rb_obj_is_kind_of(GET_SELF(), rb_class_real(klass))) {
+		if (!rb_obj_is_kind_of(GET_SELF(), rb_class_real(me->defined_class))) {
 		    break;
 		}
 	      case METHOD_VISI_PUBLIC:
-- 
cgit v0.10.2


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

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