Skip to content

Ripper::SexpBuilder#parse produces invalid objects in presence of method calls #7

Open
stcrocco opened this Issue Oct 31, 2011 · 0 comments

1 participant

@stcrocco

In ruby 1.8.7-p352, using Ripper::SexpBuilder#parse with code containing method calls with the usual dot notation produces an array with elements whose inspect method causes ruby to crash. For example, the following code

require 'ripper'
Ripper::SexpBuilder.new("a.b").parse.inspect

causes the crash. Calling inspect recursively on each element of the array indicates that the problem arises on the :"." node. Using to_s rather than inspect, raises the following exception:

ArgumentError: NULL pointer given

Ripper from ruby 1.9 works correctly. Running ruby through gdb produces the following backtrace (on gentoo linux 64 bit compiled with gcc 4.5.3):


Program received signal SIGSEGV, Segmentation fault.
0x00007ffff77d2571 in __strlen_sse2 () from /lib64/libc.so.6
(gdb) bt
#0  0x00007ffff77d2571 in __strlen_sse2 () from /lib64/libc.so.6
#1  0x00007ffff7b40c5a in sym_inspect (sym=<optimized out>) at object.c:1167
#2  0x00007ffff7b140ce in rb_call0 (klass=140737353860000, recv=11790, id=3145, oid=<optimized out>, argc=0, argv=0x0, body=0x7ffff7fbc210, flags=0) at eval.c:5938
#3  0x00007ffff7b142ad in rb_call (klass=140737353860000, recv=11790, mid=3145, argc=0, argv=0x0, scope=1, self=<optimized out>) at eval.c:6186
#4  0x00007ffff7b14968 in vafuncall (recv=<optimized out>, mid=<optimized out>, n=<optimized out>, ar=<optimized out>) at eval.c:6263
#5  0x00007ffff7b14c05 in rb_funcall (recv=<optimized out>, mid=<optimized out>, n=<optimized out>) at eval.c:6280
#6  0x00007ffff7b420e6 in rb_inspect (obj=<optimized out>) at object.c:334
#7  0x00007ffff7af53b6 in inspect_ary (ary=140737353666400) at array.c:1568
#8  0x00007ffff7b0f372 in rb_ensure (b_proc=0x7ffff7af4210 <inspect_call>, data1=140737488333456, e_proc=0x7ffff7af8040 <inspect_ensure>, data2=140737353666400) at eval.c:5581
#9  0x00007ffff7af8c82 in rb_protect_inspect (func=0x7ffff7af5360 <inspect_ary>, obj=140737353666400, arg=0) at array.c:1544
#10 0x00007ffff7b140ce in rb_call0 (klass=140737353800760, recv=140737353666400, id=3145, oid=<optimized out>, argc=0, argv=0x0, body=0x7ffff7fada30, flags=0) at eval.c:5938
#11 0x00007ffff7b142ad in rb_call (klass=140737353800760, recv=140737353666400, mid=3145, argc=0, argv=0x0, scope=1, self=<optimized out>) at eval.c:6186
#12 0x00007ffff7b14968 in vafuncall (recv=<optimized out>, mid=<optimized out>, n=<optimized out>, ar=<optimized out>) at eval.c:6263
#13 0x00007ffff7b14c05 in rb_funcall (recv=<optimized out>, mid=<optimized out>, n=<optimized out>) at eval.c:6280
#14 0x00007ffff7b420e6 in rb_inspect (obj=<optimized out>) at object.c:334
#15 0x00007ffff7af53b6 in inspect_ary (ary=140737353666120) at array.c:1568
#16 0x00007ffff7b0f372 in rb_ensure (b_proc=0x7ffff7af4210 <inspect_call>, data1=140737488336416, e_proc=0x7ffff7af8040 <inspect_ensure>, data2=140737353666120) at eval.c:5581
#17 0x00007ffff7af8c82 in rb_protect_inspect (func=0x7ffff7af5360 <inspect_ary>, obj=140737353666120, arg=0) at array.c:1544
#18 0x00007ffff7b140ce in rb_call0 (klass=140737353800760, recv=140737353666120, id=3145, oid=<optimized out>, argc=0, argv=0x0, body=0x7ffff7fada30, flags=0) at eval.c:5938
#19 0x00007ffff7b142ad in rb_call (klass=140737353800760, recv=140737353666120, mid=3145, argc=0, argv=0x0, scope=1, self=<optimized out>) at eval.c:6186
#20 0x00007ffff7b14968 in vafuncall (recv=<optimized out>, mid=<optimized out>, n=<optimized out>, ar=<optimized out>) at eval.c:6263
#21 0x00007ffff7b14c05 in rb_funcall (recv=<optimized out>, mid=<optimized out>, n=<optimized out>) at eval.c:6280
#22 0x00007ffff7b420e6 in rb_inspect (obj=<optimized out>) at object.c:334
#23 0x00007ffff7af53b6 in inspect_ary (ary=140737353666040) at array.c:1568
#24 0x00007ffff7b0f372 in rb_ensure (b_proc=0x7ffff7af4210 <inspect_call>, data1=140737488339376, e_proc=0x7ffff7af8040 <inspect_ensure>, data2=140737353666040) at eval.c:5581
#25 0x00007ffff7af8c82 in rb_protect_inspect (func=0x7ffff7af5360 <inspect_ary>, obj=140737353666040, arg=0) at array.c:1544
#26 0x00007ffff7b140ce in rb_call0 (klass=140737353800760, recv=140737353666040, id=3145, oid=<optimized out>, argc=0, argv=0x0, body=0x7ffff7fada30, flags=0) at eval.c:5938
#27 0x00007ffff7b142ad in rb_call (klass=140737353800760, recv=140737353666040, mid=3145, argc=0, argv=0x0, scope=0, self=<optimized out>) at eval.c:6186
#28 0x00007ffff7b19668 in rb_eval (self=140737353855640, n=0x7ffff7f35170) at eval.c:3516
#29 0x00007ffff7b1fdbb in ruby_exec_internal () at eval.c:1664
#30 0x00007ffff7b1fe05 in ruby_exec () at eval.c:1684
#31 0x00007ffff7b22555 in ruby_run () at eval.c:1694
#32 0x000000000040095c in main (argc=1, argv=<optimized out>, envp=<optimized out>) at main.c:48
@mislav mislav added a commit to tmm1/ripper-tags that referenced this issue Aug 25, 2013
@mislav mislav fix superclass detection on Ruby 1.8
In case of `Class.new klass`, we don't want `klass` being interpreted as
a name of superclass since it's not a constant.

The unit test for this failed on Ruby 1.8 since the backport of Ripper
parses that line differently than its 1.9 equivalent; it interprets
`klass` as `var_ref` rather than `vcall`. This was tricky to debug due
to lsegal/ripper18#7

This quick workaround simply disallows superclass names that don't look
like a Ruby constant.
0c7ab9d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.