Project

General

Profile

Actions

Bug #9663

closed

Segfault with alias_method and include

Added by eagletmt (Kohei Suzuki) almost 11 years ago. Updated over 10 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.2.0dev (2014-03-20 trunk 45367) [x86_64-linux]
[ruby-core:61635]

Description

The following code results in segfault since r45367.

module M
  alias_method :orig_to_s, :to_s
  def to_s
    'to_s'
  end
end

class C
  include M
end

C.new.orig_to_s
% ruby -v segv.rb
ruby 2.2.0dev (2014-03-20 trunk 45366) [x86_64-linux]
% ruby -v segv.rb
ruby 2.2.0dev (2014-03-20 trunk 45367) [x86_64-linux]
segv.rb:12: [BUG] Segmentation fault at 0x00000000000000
ruby 2.2.0dev (2014-03-20 trunk 45367) [x86_64-linux]

-- Control frame information -----------------------------------------------
c:0002 p:0033 s:0005 E:000928 EVAL   segv.rb:12 [FINISH]
c:0001 p:0000 s:0002 E:001878 TOP    [FINISH]

-- Ruby level backtrace information ----------------------------------------
segv.rb:12:in `<main>'

-- C level backtrace information -------------------------------------------
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(rb_print_backtrace+0x19) [0x7fbba1bae386] vm_dump.c:685
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(rb_vm_bugreport+0x93) [0x7fbba1bae45b] vm_dump.c:825
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(_L_unlock_51+0x17) [0x7fbba1a415ab] error.c:312
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(freopen+0x155) [0x7fbba1a41725] error.c:339
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(sigsegv+0x7f) [0x7fbba1b21860] signal.c:704
/usr/lib/libpthread.so.0(+0xf880) [0x7fbba17c2880]
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(rb_method_entry_get_without_cache+0x3e) [0x7fbba1ba0469] vm_method.c:582
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(rb_method_entry+0xb8) [0x7fbba1ba0631] vm_method.c:650
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(vm_search_method+0x7f) [0x7fbba1b930c9] vm_insnhelper.c:834
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(vm_exec_core+0x2794) [0x7fbba1b99f40] insns.def:1027
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(vm_exec+0xbe) [0x7fbba1ba9d5d] vm.c:1327
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(rb_iseq_eval_main+0x34) [0x7fbba1baacca] vm.c:1585
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(_L_unlock_335+0x11) [0x7fbba1a47339] eval.c:251
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(_L_unlock_2193+0xc) [0x7fbba1a47452] eval.c:316
/home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2(_L_lock_2146+0x15) [0x7fbba1a47425] eval.c:308
ruby() [0x400a4e]
/usr/lib/libc.so.6(__libc_start_main+0xf5) [0x7fbba0a79b05]
ruby() [0x400919]

-- Other runtime information -----------------------------------------------

* Loaded script: segv.rb

* Loaded features:

    0 enumerator.so
    1 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
    2 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
    3 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/rbconfig.rb
    4 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/compatibility.rb
    5 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/defaults.rb
    6 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/deprecate.rb
    7 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/errors.rb
    8 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/version.rb
    9 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/requirement.rb
   10 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/platform.rb
   11 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/basic_specification.rb
   12 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/stub_specification.rb
   13 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/util/stringio.rb
   14 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/specification.rb
   15 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/exceptions.rb
   16 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/core_ext/kernel_gem.rb
   17 thread.rb
   18 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/thread.so
   19 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/monitor.rb
   20 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems/core_ext/kernel_require.rb
   21 /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/rubygems.rb

* Process memory map:

00400000-00401000 r-xp 00000000 08:34 1474345                            /home/eagletmt/.rbenv/versions/r45367/bin/ruby
00600000-00601000 rw-p 00000000 08:34 1474345                            /home/eagletmt/.rbenv/versions/r45367/bin/ruby
02031000-024b6000 rw-p 00000000 00:00 0                                  [heap]
7fbb9ffc3000-7fbb9ffd8000 r-xp 00000000 08:33 814588                     /usr/lib/libgcc_s.so.1
7fbb9ffd8000-7fbba01d8000 ---p 00015000 08:33 814588                     /usr/lib/libgcc_s.so.1
7fbba01d8000-7fbba01d9000 rw-p 00015000 08:33 814588                     /usr/lib/libgcc_s.so.1
7fbba01d9000-7fbba01dc000 r-xp 00000000 08:34 1476107                    /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/thread.so
7fbba01dc000-7fbba03db000 ---p 00003000 08:34 1476107                    /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/thread.so
7fbba03db000-7fbba03dc000 rw-p 00002000 08:34 1476107                    /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/thread.so
7fbba03dc000-7fbba03de000 r-xp 00000000 08:34 1476077                    /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
7fbba03de000-7fbba05de000 ---p 00002000 08:34 1476077                    /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
7fbba05de000-7fbba05df000 rw-p 00002000 08:34 1476077                    /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/enc/trans/transdb.so
7fbba05df000-7fbba05e1000 r-xp 00000000 08:34 1476040                    /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
7fbba05e1000-7fbba07e0000 ---p 00002000 08:34 1476040                    /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
7fbba07e0000-7fbba07e1000 rw-p 00001000 08:34 1476040                    /home/eagletmt/.rbenv/versions/r45367/lib/ruby/2.2.0/x86_64-linux/enc/encdb.so
7fbba07e1000-7fbba0a58000 r--p 00000000 08:33 843234                     /usr/lib/locale/locale-archive
7fbba0a58000-7fbba0bf6000 r-xp 00000000 08:33 789942                     /usr/lib/libc-2.19.so
7fbba0bf6000-7fbba0df6000 ---p 0019e000 08:33 789942                     /usr/lib/libc-2.19.so
7fbba0df6000-7fbba0dfa000 r--p 0019e000 08:33 789942                     /usr/lib/libc-2.19.so
7fbba0dfa000-7fbba0dfc000 rw-p 001a2000 08:33 789942                     /usr/lib/libc-2.19.so
7fbba0dfc000-7fbba0e00000 rw-p 00000000 00:00 0 
7fbba0e00000-7fbba0f00000 r-xp 00000000 08:33 789857                     /usr/lib/libm-2.19.so
7fbba0f00000-7fbba10ff000 ---p 00100000 08:33 789857                     /usr/lib/libm-2.19.so
7fbba10ff000-7fbba1100000 r--p 000ff000 08:33 789857                     /usr/lib/libm-2.19.so
7fbba1100000-7fbba1101000 rw-p 00100000 08:33 789857                     /usr/lib/libm-2.19.so
7fbba1101000-7fbba1109000 r-xp 00000000 08:33 789974                     /usr/lib/libcrypt-2.19.so
7fbba1109000-7fbba1308000 ---p 00008000 08:33 789974                     /usr/lib/libcrypt-2.19.so
7fbba1308000-7fbba1309000 r--p 00007000 08:33 789974                     /usr/lib/libcrypt-2.19.so
7fbba1309000-7fbba130a000 rw-p 00008000 08:33 789974                     /usr/lib/libcrypt-2.19.so
7fbba130a000-7fbba1338000 rw-p 00000000 00:00 0 
7fbba1338000-7fbba133b000 r-xp 00000000 08:33 789888                     /usr/lib/libdl-2.19.so
7fbba133b000-7fbba153a000 ---p 00003000 08:33 789888                     /usr/lib/libdl-2.19.so
7fbba153a000-7fbba153b000 r--p 00002000 08:33 789888                     /usr/lib/libdl-2.19.so
7fbba153b000-7fbba153c000 rw-p 00003000 08:33 789888                     /usr/lib/libdl-2.19.so
7fbba153c000-7fbba15a9000 r-xp 00000000 08:33 793483                     /usr/lib/libgmp.so.10.1.3
7fbba15a9000-7fbba17a9000 ---p 0006d000 08:33 793483                     /usr/lib/libgmp.so.10.1.3
7fbba17a9000-7fbba17aa000 r--p 0006d000 08:33 793483                     /usr/lib/libgmp.so.10.1.3
7fbba17aa000-7fbba17b3000 rw-p 0006e000 08:33 793483                     /usr/lib/libgmp.so.10.1.3
7fbba17b3000-7fbba17cb000 r-xp 00000000 08:33 789960                     /usr/lib/libpthread-2.19.so
7fbba17cb000-7fbba19ca000 ---p 00018000 08:33 789960                     /usr/lib/libpthread-2.19.so
7fbba19ca000-7fbba19cb000 r--p 00017000 08:33 789960                     /usr/lib/libpthread-2.19.so
7fbba19cb000-7fbba19cc000 rw-p 00018000 08:33 789960                     /usr/lib/libpthread-2.19.so
7fbba19cc000-7fbba19d0000 rw-p 00000000 00:00 0 
7fbba19d0000-7fbba1c7a000 r-xp 00000000 08:34 1474346                    /home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2.0
7fbba1c7a000-7fbba1e79000 ---p 002aa000 08:34 1474346                    /home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2.0
7fbba1e79000-7fbba1e82000 rw-p 002a9000 08:34 1474346                    /home/eagletmt/.rbenv/versions/r45367/lib/libruby.so.2.2.0
7fbba1e82000-7fbba1ea8000 rw-p 00000000 00:00 0 
7fbba1ea8000-7fbba1ec8000 r-xp 00000000 08:33 789919                     /usr/lib/ld-2.19.so
7fbba1f97000-7fbba209d000 rw-p 00000000 00:00 0 
7fbba20c1000-7fbba20c3000 rw-p 00000000 00:00 0 
7fbba20c3000-7fbba20c4000 ---p 00000000 00:00 0 
7fbba20c4000-7fbba20c8000 rw-p 00000000 00:00 0                          [stack:17257]
7fbba20c8000-7fbba20c9000 r--p 00020000 08:33 789919                     /usr/lib/ld-2.19.so
7fbba20c9000-7fbba20ca000 rw-p 00021000 08:33 789919                     /usr/lib/ld-2.19.so
7fbba20ca000-7fbba20cb000 rw-p 00000000 00:00 0 
7fffe5b52000-7fffe5b73000 rw-p 00000000 00:00 0 
7fffe5bfe000-7fffe5c00000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]


[NOTE]
You may have encountered a bug in the Ruby interpreter or extension libraries.
Bug reports are welcome.
For details: http://www.ruby-lang.org/bugreport.html

Related issues 1 (0 open1 closed)

Related to Ruby master - Bug #9475: Behavior change with include + super + alias_method between 1.9.x and 2.x Closednobu (Nobuyoshi Nakada)02/03/2014Actions

Updated by eagletmt (Kohei Suzuki) almost 11 years ago

Is NULL-check needed?

diff --git a/vm_method.c b/vm_method.c
index 2279190..6516a0b 100644
--- a/vm_method.c
+++ b/vm_method.c
@@ -578,7 +578,7 @@ rb_method_entry_get_without_cache(VALUE klass, ID id,
     VALUE defined_class;
     rb_method_entry_t *me = search_method(klass, id, &defined_class);
 
-    if (me) {
+    if (me && me->klass) {
 	switch (BUILTIN_TYPE(me->klass)) {
 	  case T_CLASS:
 	    if (RBASIC(klass)->flags & FL_SINGLETON) break;

Updated by nobu (Nobuyoshi Nakada) almost 11 years ago

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

Applied in changeset r45387.


vm_method.c: check if klass is 0

  • vm_method.c (rb_method_entry_get_without_cache): me->klass is 0
    for a method aliased in a module. [ruby-core:61636] [Bug #9663]

Updated by nagachika (Tomoyuki Chikanaga) almost 11 years ago

  • Related to Bug #9475: Behavior change with include + super + alias_method between 1.9.x and 2.x added

Updated by usa (Usaku NAKAMURA) over 10 years ago

  • Backport changed from 2.0.0: UNKNOWN, 2.1: UNKNOWN to 2.0.0: DONE, 2.1: DONE
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0