Backport #8966

SEGV when a refined method is undefined by undef

Added by Shugo Maeda 7 months ago. Updated 6 months ago.

[ruby-core:57466]
Status:Closed
Priority:Normal
Assignee:Tomoyuki Chikanaga

Description

=begin
The following code causes SEGV:

module Foo
refine Object do
def foo
puts "foo"
end
end
end

using Foo

class Object
undef foo
end

foo

I guess undef is not aware of refinements.
=end

Associated revisions

Revision 43143
Added by Tomoyuki Chikanaga 7 months ago

merge revision(s) 43090,43091: [Backport #8966]

* vm_method.c (rb_undef): raise a NameError if the original method
  of a refined method is not defined. 

* vm_insnhelper.c (rb_method_entry_eq): added NULL check to avoid SEGV.

* test/ruby/test_refinement.rb: related test.
  of a refined method is not defined.

History

#1 Updated by Nobuyoshi Nakada 7 months ago

  • Description updated (diff)

=begin
What should happen in that case?
Printing (({"foo"})), or raising a (({NameError}))?
=end

#2 Updated by Shugo Maeda 7 months ago

nobu (Nobuyoshi Nakada) wrote:

What should happen in that case?
Printing (({"foo"})), or raising a (({NameError}))?

`undef foo' should raise a NameError because foo is not defined in the original class.

#3 Updated by Tomoyuki Chikanaga 7 months ago

  • Status changed from Assigned to Closed
  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN to 1.9.3: UNKNOWN, 2.0.0: REQUIRED

committed at r43090.
And it should be backported to ruby20_0.

#4 Updated by Tomoyuki Chikanaga 7 months ago

  • Tracker changed from Bug to Backport
  • Project changed from ruby-trunk to Backport200
  • Category deleted (core)
  • Status changed from Closed to Assigned
  • Assignee changed from Shugo Maeda to Tomoyuki Chikanaga
  • Target version deleted (2.1.0)

#5 Updated by Shugo Maeda 7 months ago

nagachika (Tomoyuki Chikanaga) wrote:

committed at r43090.
And it should be backported to ruby20_0.

Ah, I forgot to add the bug number to the commit log of r43090. Thanks.

#6 Updated by Tomoyuki Chikanaga 6 months ago

  • Status changed from Assigned to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r43143.
Shugo, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


merge revision(s) 43090,43091: [Backport #8966]

* vm_method.c (rb_undef): raise a NameError if the original method
  of a refined method is not defined. 

* vm_insnhelper.c (rb_method_entry_eq): added NULL check to avoid SEGV.

* test/ruby/test_refinement.rb: related test.
  of a refined method is not defined.

Also available in: Atom PDF