Bugs item #9525, was opened at 2007-03-24 22:16
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=9525&group_id=426

Category: None
Group: 1.9.x
Status: Open
Resolution: None
Priority: 3
Submitted By: NM RN (knyt)
Assigned to: Nobody (None)
Summary: Inclusion of OpenSSL makes Ruby segfault

Initial Comment:
Adding 'openssl' to ext/Setup produces this on any execution:

###
-- stack frame ------------
-- control frame ----------
c:0001 p:---- s:0000 b:-001 l:000000 d:000000 ------ 
---------------------------
-- backtrace of native function call (Use addr2line) --
0x815a5ea
0x80ce070
0x8133bf8
0xffffe420
0x807f005
0x806ab8f
0x8131c9b
0x8133594
0x813277d
0x81330f7
0x80d48ae
0x806aa6a
0xb7c46878
0x806a9a1
-------------------------------------------------------
[BUG] Segmentation fault
ruby 1.9.0 (2007-03-23) [i686-linux]

Aborted
###

Running those addresses through addr2line on {src}/ruby:

###
/home/kennyt/ruby/vm_dump.c:603
/home/kennyt/ruby/error.c:164
/home/kennyt/ruby/signal.c:459
??:0
/home/kennyt/ruby/ext/openssl/ossl_asn1.c:1123
ext/extinit.c:15
/home/kennyt/ruby/ruby.c:374
/home/kennyt/ruby/ruby.c:1009
/home/kennyt/ruby/ruby.c:881
/home/kennyt/ruby/ruby.c:1274
/home/kennyt/ruby/eval.c:146
/home/kennyt/ruby/main.c:47
??:0
??:0
###

This crash has been in the trunk for a while now, so I guess it hasn't been noticed.

OpenSSL 0.9.8d 28 Sep 2006
OpenSSL 0.9.8e 23 Feb 2007

This is the test file:
###
puts 'test'
###

./miniruby test.rb, of course, works fine.

----------------------------------------------------------------------

>Comment By: NM RN (knyt)
Date: 2007-04-09 19:48

Message:
I still get that crash.

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1212369232 (LWP 24166)]
0x080dd047 in rb_attr (klass=3081702560, id=16080, read=1,
write=1, ex=2)
    at eval_intern.h:232
232         return th_get_cref(th, cfp->iseq, cfp);
(gdb) bt
#0  0x080dd047 in rb_attr (klass=3081702560, id=16080,
read=1, write=1, ex=2)
    at eval_intern.h:232
#1  0x08080955 in Init_ossl_asn1 () at ossl_asn1.c:1122
#2  0x0806c4bf in Init_ext () at ext/extinit.c:15
#3  0x0813904b in require_libraries () at ruby.c:373
#4  0x0813a86e in load_file (fname=0xbf9f1436 "test.rb", 
    script=<value optimized out>) at ruby.c:1009
#5  0x08139b2d in proc_options (argc=<value optimized out>, 
    argv=<value optimized out>) at ruby.c:878
#6  0x0813a4a7 in ruby_process_options (argc=2,
argv=0xbf9efcb4) at ruby.c:1272
#7  0x080dbc4e in ruby_options (argc=2, argv=0xbf9efcb4) at
eval.c:140
#8  0x0806c39a in main (argc=Cannot access memory at address 0x0
) at main.c:46


0x816199a
0x80d5410
0x813afa8
0xffffe420
0x8080955
0x806c4bf
0x813904b
0x813a86e
0x8139b2d
0x813a4a7
0x80dbc4e
0x806c39a
0xb7cb7878
0x806c2d1

./ruby test.rb 2>&1 | grep 0x | xargs addr2line -e ruby

vm_dump.c:603
error.c:164
signal.c:459
??:0
ext/openssl/ossl_asn1.c:1123
ext/extinit.c:15
ruby.c:374
ruby.c:1013
ruby.c:881
ruby.c:1274
eval.c:146
main.c:47
??:0
??:0

----------------------------------------------------------------------

Comment By: Technorama Ltd. (technorama)
Date: 2007-04-09 19:22

Message:
There have been a few updates recently.  The problem has probably been fixed unless it's specific to your platform or configure args.


----------------------------------------------------------------------

Comment By: Abhisek Datta (abhisek)
Date: 2007-03-25 19:44

Message:
Looks like a NULL pointer dereference which is triggered only when OpenSSL is configured as a static extension..

(gdb) r -e 'print "Hello"'
Starting program: /home/me/ROOT/personal/oss/ruby/ruby2/ruby -e 'print "Hello"'
Failed to read a valid object file image from memory.
[Thread debugging using libthread_db enabled]
[New Thread -1212098368 (LWP 11701)]
[New Thread -1208841312 (LWP 11704)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1212098368 (LWP 11701)]
0x0809af17 in rb_attr (klass=3082005320, id=14760, read=1, write=1, ex=2) at eval_intern.h:232
232         return th_get_cref(th, cfp->iseq, cfp);
(gdb) x/i $eip
0x809af17 <rb_attr+247>:        mov    0xc(%eax),%eax
(gdb) i r $eax
eax            0x0      0
(gdb)                         

I guess yarv is not initialized when Init_ext() is called? since th_get_ruby_level_cfp() returns NULL..

----------------------------------------------------------------------

Comment By: NM RN (knyt)
Date: 2007-03-24 22:19

Message:
user@host ~/ruby $ gdb ./ruby         
GNU gdb 6.6
Copyright (C) 2006 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public
License, and you are
welcome to change it and/or distribute copies of it under
certain conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show
warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
Using host libthread_db library "/lib/libthread_db.so.1".
(gdb) run test.rb
Starting program: /home/user/ruby/ruby test.rb
[Thread debugging using libthread_db enabled]
[New Thread -1211832656 (LWP 6409)]
[New Thread -1211835488 (LWP 6412)]

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread -1211832656 (LWP 6409)]
0x080d6097 in rb_attr (klass=3082248120, id=15488, read=1,
write=1, ex=2)
    at eval_intern.h:232
232         return th_get_cref(th, cfp->iseq, cfp);
(gdb) bt
#0  0x080d6097 in rb_attr (klass=3082248120, id=15488,
read=1, write=1, ex=2)
    at eval_intern.h:232
#1  0x0807f325 in Init_ossl_asn1 () at ossl_asn1.c:1122
#2  0x0806aeaf in Init_ext () at ext/extinit.c:15
#3  0x0813208b in require_libraries () at ruby.c:373
#4  0x08133984 in load_file (fname=0xbfe37425 "test.rb", 
    script=<value optimized out>) at ruby.c:1009
#5  0x08132b6d in proc_options (argc=<value optimized out>, 
    argv=<value optimized out>) at ruby.c:878
#6  0x081334e7 in ruby_process_options (argc=2,
argv=0xbfe370e4) at ruby.c:1272
#7  0x080d4c9e in ruby_options (argc=2, argv=0xbfe370e4) at
eval.c:140
#8  0x0806ad8a in main (argc=Cannot access memory at address 0x0
) at main.c:46
(gdb) 


----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=9525&group_id=426