summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornagachika <nagachika@ruby-lang.org>2020-08-01 17:33:56 +0900
committernagachika <nagachika@ruby-lang.org>2020-08-01 17:33:56 +0900
commit23d130a9ddcaf766d6ce309f8518b434a2537fc1 (patch)
tree55c67e3ca38c6145be68346701c8a56d71ab78ac
parent315f1ee8a80680fd7aff5fa27abfd965d1906809 (diff)
merge revision(s) d05f04d27dd86c67e4a8dfff4392f806cf577bdf: [Backport #16931]
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]
-rw-r--r--test/ruby/test_defined.rb1
-rw-r--r--version.h2
-rw-r--r--vm_insnhelper.c2
3 files changed, 3 insertions, 2 deletions
diff --git a/test/ruby/test_defined.rb b/test/ruby/test_defined.rb
index 387472a62d..e1571d5714 100644
--- a/test/ruby/test_defined.rb
+++ b/test/ruby/test_defined.rb
@@ -59,6 +59,7 @@ class TestDefined < Test::Unit::TestCase
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/version.h b/version.h
index 8b6e0eeaed..8c5893a5af 100644
--- a/version.h
+++ b/version.h
@@ -2,7 +2,7 @@
# define RUBY_VERSION_MINOR RUBY_API_VERSION_MINOR
#define RUBY_VERSION_TEENY 1
#define RUBY_RELEASE_DATE RUBY_RELEASE_YEAR_STR"-"RUBY_RELEASE_MONTH_STR"-"RUBY_RELEASE_DAY_STR
-#define RUBY_PATCHLEVEL 116
+#define RUBY_PATCHLEVEL 117
#define RUBY_RELEASE_YEAR 2020
#define RUBY_RELEASE_MONTH 8
diff --git a/vm_insnhelper.c b/vm_insnhelper.c
index 2ac006a605..c0d9092a67 100644
--- a/vm_insnhelper.c
+++ b/vm_insnhelper.c
@@ -3551,7 +3551,7 @@ vm_defined(rb_execution_context_t *ec, rb_control_frame_t *reg_cfp, rb_num_t op_
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: