Ruby native extension aborts with __stack_chk_fail in OSX
---------------------------------------------------------

                 Key: THRIFT-1400
                 URL: https://issues.apache.org/jira/browse/THRIFT-1400
             Project: Thrift
          Issue Type: Bug
          Components: Ruby - Library
    Affects Versions: 0.7, 0.8
         Environment: Mac OSX 10.7.2
Xcode 4.2
MRI 1.9.3-rc1 built with clang, 64 bit

            Reporter: Carlos Carrasco
         Attachments: fix-field-value-buf.diff

get_field_value and set_field_value in struct.c apparently allocate one less 
byte than is required when building the field name, which I guess it works most 
of the time everywhere since there is nothing else in the stack, but OSX+clang 
appear to be serious about it.

My patch follows the rationale that RSTRING_LEN does not include the 0-ended 
length, and apparently in Ruby 1.9(.3?) RSTRING_PTR is not zero-terminated, so 
I add one extra byte to the char[] and fix the passed buffer length to be 
actually the string length plus the extra byte for the zero.

Stack trace:

#0  0x00007fff9504bce2 in __pthread_kill ()
#1  0x00007fff93d617d2 in pthread_kill ()
#2  0x00007fff93d52b4a in __abort ()
#3  0x00007fff93d4f070 in __stack_chk_fail ()
#4  0x000000010077a417 in set_field_value (obj=<value temporarily unavailable, 
due to optimizations>, field_name=<value temporarily unavailable, due to 
optimizations>, value=<value temporarily unavailable, due to optimizations>) at 
struct.c:426
#5  0x0000000100779141 in rb_thrift_struct_read (self=4306092880, 
protocol=4306073480) at struct.c:592
#6  0x0000000100779cb9 in read_anything (protocol=4306073480, ttype=<value 
temporarily unavailable, due to optimizations>, field_info=<value temporarily 
unavailable, due to optimizations>) at struct.c:469
#7  0x0000000100779a5a in read_anything (protocol=4306073480, ttype=<value 
temporarily unavailable, due to optimizations>, field_info=4304975600) at 
struct.c:522
#8  0x0000000100779132 in rb_thrift_struct_read (self=4306096120, 
protocol=4306073480) at struct.c:592
#9  0x0000000100779cb9 in read_anything (protocol=4306073480, ttype=<value 
temporarily unavailable, due to optimizations>, field_info=<value temporarily 
unavailable, due to optimizations>) at struct.c:469
#10 0x0000000100779132 in rb_thrift_struct_read (self=4306097000, 
protocol=4306073480) at struct.c:592
#11 0x000000010013e7c5 in vm_call_cfunc [inlined] () at 
/Users/ccm/.rvm/src/ruby-1.9.3-rc1/vm_insnhelper.c:404
#12 0x000000010013e7c5 in vm_call_method (th=0x100301b10, cfp=0x1004ffb30, 
num=1, blockptr=0x0, flag=<value temporarily unavailable, due to 
optimizations>, id=<value temporarily unavailable, due to optimizations>, 
me=<value temporarily unavailable, due to optimizations>, recv=<value 
temporarily unavailable, due to optimizations>) at vm_insnhelper.c:534
#13 0x000000010012f5ee in vm_exec_core (th=0x100301b10, initial=<value 
temporarily unavailable, due to optimizations>) at vm.inc:1015
#14 0x0000000100138c94 in vm_exec (th=0x100301b10) at vm.c:1220
#15 0x00000001001395ab in rb_iseq_eval_main (iseqval=4304251720) at vm.c:1461
#16 0x000000010003701f in ruby_exec_internal (n=<value temporarily unavailable, 
due to optimizations>) at eval.c:204
#17 0x0000000100036f67 in ruby_run_node (n=0x1008dab48) at eval.c:251
#18 0x0000000100000edf in main (argc=2, argv=0x7fff5fbff838) at main.c:38

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators: 
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to