Project

General

Profile

Bug #13776

Refined methods ignore visibility of inherited methods

Added by Mon_Ouie (Mon ouïe) over 2 years ago. Updated almost 2 years ago.

Status:
Closed
Priority:
Normal
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.0dev (2017-07-28 trunk 59438) [x86_64-linux]
[ruby-core:82209]

Description

This bug was pointed out by al2o3-cr on the #ruby IRC channel on freenode. The following code sleeps for 3 seconds, even though String#sleep is a private method.

module Test
  refine String do
    def sleep; end
  end
end

puts "start"
"".sleep 3
puts "end"

This happens because vm_call_method_each_type, when running a method of type VM_METHOD_TYPE_REFINED, uses vm_call_zsuper to call inherited methods, which does not check the visibility of the method and directly executes it. I attached a patch which changes this code path and uses vm_call_method to trigger the code that honors method visibilities. I have not played extensively with this patch, but it at least does not seem to break any existing unit tests.


Files

refinement.patch (1.74 KB) refinement.patch Mon_Ouie (Mon ouïe), 07/29/2017 09:18 AM

Associated revisions

Revision 59444
Added by nobu (Nobuyoshi Nakada) over 2 years ago

adjust indent [ci skip]

  • vm_insnhelper.c (vm_call_method_each_type): adjust indent of a block in switch.

Revision 3449d4fa
Added by nobu (Nobuyoshi Nakada) over 2 years ago

visibility of inherited method

  • vm_insnhelper.c (vm_call_method_each_type): honor the original visibility of inherited methods when a refinement is defined but not activated. [ruby-core:82209] [Bug #13776]

Author: Mon_Ouie (Mon ouïe) mon.ouie@gmail.com

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59445 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 59445
Added by nobu (Nobuyoshi Nakada) over 2 years ago

visibility of inherited method

  • vm_insnhelper.c (vm_call_method_each_type): honor the original visibility of inherited methods when a refinement is defined but not activated. [ruby-core:82209] [Bug #13776]

Author: Mon_Ouie (Mon ouïe) mon.ouie@gmail.com

Revision 59445
Added by nobu (Nobuyoshi Nakada) over 2 years ago

visibility of inherited method

  • vm_insnhelper.c (vm_call_method_each_type): honor the original visibility of inherited methods when a refinement is defined but not activated. [ruby-core:82209] [Bug #13776]

Author: Mon_Ouie (Mon ouïe) mon.ouie@gmail.com

Revision 59445
Added by nobu (Nobuyoshi Nakada) over 2 years ago

visibility of inherited method

  • vm_insnhelper.c (vm_call_method_each_type): honor the original visibility of inherited methods when a refinement is defined but not activated. [ruby-core:82209] [Bug #13776]

Author: Mon_Ouie (Mon ouïe) mon.ouie@gmail.com

Revision db22ab15
Added by nagachika (Tomoyuki Chikanaga) almost 2 years ago

merge revision(s) 59444,59445: [Backport #13776]

    adjust indent [ci skip]

    * vm_insnhelper.c (vm_call_method_each_type): adjust indent of a
      block in switch.

    visibility of inherited method

    * vm_insnhelper.c (vm_call_method_each_type): honor the original
      visibility of inherited methods when a refinement is defined but
      not activated.  [ruby-core:82209] [Bug #13776]

    Author:    Mon_Ouie (Mon ouie) <mon.ouie@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_4@61436 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 61436
Added by nagachika (Tomoyuki Chikanaga) almost 2 years ago

merge revision(s) 59444,59445: [Backport #13776]

adjust indent [ci skip]

* vm_insnhelper.c (vm_call_method_each_type): adjust indent of a
  block in switch.

visibility of inherited method

* vm_insnhelper.c (vm_call_method_each_type): honor the original
  visibility of inherited methods when a refinement is defined but
  not activated.  [ruby-core:82209] [Bug #13776]

Author:    Mon_Ouie (Mon ouie) <mon.ouie@gmail.com>

Revision 1aee5acd
Added by usa (Usaku NAKAMURA) almost 2 years ago

merge revision(s) 59444,59445: [Backport #13776]

    adjust indent [ci skip]

    * vm_insnhelper.c (vm_call_method_each_type): adjust indent of a
      block in switch.

    visibility of inherited method

    * vm_insnhelper.c (vm_call_method_each_type): honor the original
      visibility of inherited methods when a refinement is defined but
      not activated.  [ruby-core:82209] [Bug #13776]

    Author:    Mon_Ouie (Mon ouie) <mon.ouie@gmail.com>

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@62134 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 62134
Added by usa (Usaku NAKAMURA) almost 2 years ago

merge revision(s) 59444,59445: [Backport #13776]

adjust indent [ci skip]

* vm_insnhelper.c (vm_call_method_each_type): adjust indent of a
  block in switch.

visibility of inherited method

* vm_insnhelper.c (vm_call_method_each_type): honor the original
  visibility of inherited methods when a refinement is defined but
  not activated.  [ruby-core:82209] [Bug #13776]

Author:    Mon_Ouie (Mon ouie) <mon.ouie@gmail.com>

History

#1

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

  • Status changed from Open to Closed

Applied in changeset trunk|r59445.


visibility of inherited method

  • vm_insnhelper.c (vm_call_method_each_type): honor the original visibility of inherited methods when a refinement is defined but not activated. [ruby-core:82209] [Bug #13776]

Author: Mon_Ouie (Mon ouïe) mon.ouie@gmail.com

#2

Updated by nobu (Nobuyoshi Nakada) over 2 years ago

  • Backport changed from 2.2: UNKNOWN, 2.3: UNKNOWN, 2.4: UNKNOWN to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED
  • Description updated (diff)

Updated by nagachika (Tomoyuki Chikanaga) almost 2 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: REQUIRED to 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE

ruby_2_4 r61436 merged revision(s) 59444,59445.

Updated by usa (Usaku NAKAMURA) almost 2 years ago

  • Backport changed from 2.2: REQUIRED, 2.3: REQUIRED, 2.4: DONE to 2.2: REQUIRED, 2.3: DONE, 2.4: DONE

ruby_2_3 r62134 merged revision(s) 59444,59445.

Also available in: Atom PDF