Actions
Bug #14782
closedbinding.eval("proc") with &:to_s dumps core
Description
The following program dumps core.
def foo
binding.eval("proc")
end
foo(&:to_s)
VM_ENV_PROCVAL seems to be a Symbol when &:to_s is given. I'm unsure if this is intended, but anyway, Kernel#proc
with no block does not support the case.
I created a patch to make Kernel#proc
support the situation. @ko1 (Koichi Sasada), could you review this?
diff --git a/proc.c b/proc.c
index b81d14ed46..d54ccd58cb 100644
--- a/proc.c
+++ b/proc.c
@@ -709,7 +709,7 @@ proc_new(VALUE klass, int8_t is_lambda)
const VALUE *lep = rb_vm_ep_local_ep(cfp->ep);
if (VM_ENV_ESCAPED_P(lep)) {
- procval = VM_ENV_PROCVAL(lep);
+ block_handler = VM_ENV_PROCVAL(lep);
goto return_existing_proc;
}
@@ -726,11 +726,11 @@ proc_new(VALUE klass, int8_t is_lambda)
}
/* block is in cf */
+ return_existing_proc:
switch (vm_block_handler_type(block_handler)) {
case block_handler_type_proc:
procval = VM_BH_TO_PROC(block_handler);
- return_existing_proc:
if (RBASIC_CLASS(procval) == klass) {
return procval;
}
The complete dump log;
$ ruby -e '
def foo
binding.eval("proc")
end
foo(&:to_s)
'
-e:3: [BUG] Segmentation fault at 0x00000000000cb114
ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0006 p:---- s:0022 e:000021 CFUNC :proc
c:0005 p:0004 s:0018 e:000017 EVAL -e:3 [FINISH]
c:0004 p:---- s:0015 e:000014 CFUNC :eval
c:0003 p:0009 s:0010 E:000300 METHOD -e:3
c:0002 p:0017 s:0006 e:000005 EVAL -e:5 [FINISH]
c:0001 p:0000 s:0003 E:000d30 (none) [FINISH]
-- Ruby level backtrace information ----------------------------------------
-e:5:in `<main>'
-e:3:in `foo'
-e:3:in `eval'
-e:3:in `foo'
-e:3:in `proc'
-- Machine register context ------------------------------------------------
RIP: 0x00005569cb3facc5 RBP: 0x00005569cc113d80 RSP: 0x00007ffdac9f4ad0
RAX: 0x00005569cc3a2950 RBX: 0x00000000000cb10c RCX: 0x00007f6365c1e0a8
RDX: 0x00005569cc3a2950 RDI: 0x00007f6365c1e098 RSI: 0x00005569cc13a2c8
R8: 0x0000000000000000 R9: 0x0000000000000000 R10: 0x00000000000000f9
R11: 0x0000000000000001 R12: 0x00007f6365d1def0 R13: 0x00005569cc0d9308
R14: 0x00005569cc49f790 R15: 0x00005569cc13a2c8 EFL: 0x0000000000010202
-- C level backtrace information -------------------------------------------
/home/mame/local/bin/ruby(rb_vm_bugreport+0x7d3) [0x5569cb57bcd3] vm_dump.c:703
/home/mame/local/bin/ruby(rb_bug_context+0xd1) [0x5569cb56f3e1] error.c:580
/home/mame/local/bin/ruby(sigsegv+0x42) [0x5569cb458262] signal.c:928
/lib/x86_64-linux-gnu/libpthread.so.0(0x7f636593f890) [0x7f636593f890]
/home/mame/local/bin/ruby(rb_block_proc+0x105) [0x5569cb3facc5] vm_core.h:1192
/home/mame/local/bin/ruby(vm_call_cfunc+0xe1) [0x5569cb4ca6f1] vm_insnhelper.c:1918
/home/mame/local/bin/ruby(vm_call_method+0xd3) [0x5569cb4da1e3] vm_insnhelper.c:2381
/home/mame/local/bin/ruby(vm_exec_core+0x3136) [0x5569cb4d3e16] insns.def:915
/home/mame/local/bin/ruby(vm_exec+0x7d) [0x5569cb4d85ed] vm.c:1778
/home/mame/local/bin/ruby(eval_string_with_cref+0x137) [0x5569cb4dad77] vm_eval.c:1349
/home/mame/local/bin/ruby(rb_f_eval+0xde) [0x5569cb4db2ce] vm_eval.c:1370
/home/mame/local/bin/ruby(bind_eval+0x9a) [0x5569cb3f68fa] proc.c:384
/home/mame/local/bin/ruby(vm_call_cfunc+0xe1) [0x5569cb4ca6f1] vm_insnhelper.c:1918
/home/mame/local/bin/ruby(vm_call_method+0xd3) [0x5569cb4da1e3] vm_insnhelper.c:2381
/home/mame/local/bin/ruby(vm_exec_core+0x3136) [0x5569cb4d3e16] insns.def:915
/home/mame/local/bin/ruby(vm_exec+0x7d) [0x5569cb4d85ed] vm.c:1778
/home/mame/local/bin/ruby(ruby_exec_internal+0xc1) [0x5569cb355a91] eval.c:246
/home/mame/local/bin/ruby(ruby_run_node+0x2f) [0x5569cb35a26f] eval.c:310
/home/mame/local/bin/ruby(main+0x4b) [0x5569cb3557bb] ./include/ruby/intern.h:295
-- Other runtime information -----------------------------------------------
* Loaded script: -e
* Loaded features:
0 enumerator.so
1 thread.rb
2 rational.so
3 complex.so
4 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/enc/encdb.so
5 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/enc/trans/transdb.so
6 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/rbconfig.rb
7 /home/mame/local/lib/ruby/2.5.0/rubygems/compatibility.rb
8 /home/mame/local/lib/ruby/2.5.0/rubygems/defaults.rb
9 /home/mame/local/lib/ruby/2.5.0/rubygems/deprecate.rb
10 /home/mame/local/lib/ruby/2.5.0/rubygems/errors.rb
11 /home/mame/local/lib/ruby/2.5.0/rubygems/version.rb
12 /home/mame/local/lib/ruby/2.5.0/rubygems/requirement.rb
13 /home/mame/local/lib/ruby/2.5.0/rubygems/platform.rb
14 /home/mame/local/lib/ruby/2.5.0/rubygems/basic_specification.rb
15 /home/mame/local/lib/ruby/2.5.0/rubygems/stub_specification.rb
16 /home/mame/local/lib/ruby/2.5.0/rubygems/util/list.rb
17 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/stringio.so
18 /home/mame/local/lib/ruby/2.5.0/uri/rfc2396_parser.rb
19 /home/mame/local/lib/ruby/2.5.0/uri/rfc3986_parser.rb
20 /home/mame/local/lib/ruby/2.5.0/uri/common.rb
21 /home/mame/local/lib/ruby/2.5.0/uri/generic.rb
22 /home/mame/local/lib/ruby/2.5.0/uri/ftp.rb
23 /home/mame/local/lib/ruby/2.5.0/uri/http.rb
24 /home/mame/local/lib/ruby/2.5.0/uri/https.rb
25 /home/mame/local/lib/ruby/2.5.0/uri/ldap.rb
26 /home/mame/local/lib/ruby/2.5.0/uri/ldaps.rb
27 /home/mame/local/lib/ruby/2.5.0/uri/mailto.rb
28 /home/mame/local/lib/ruby/2.5.0/uri.rb
29 /home/mame/local/lib/ruby/2.5.0/rubygems/specification.rb
30 /home/mame/local/lib/ruby/2.5.0/rubygems/exceptions.rb
31 /home/mame/local/lib/ruby/2.5.0/rubygems/dependency.rb
32 /home/mame/local/lib/ruby/2.5.0/rubygems/core_ext/kernel_gem.rb
33 /home/mame/local/lib/ruby/2.5.0/monitor.rb
34 /home/mame/local/lib/ruby/2.5.0/rubygems/core_ext/kernel_require.rb
35 /home/mame/local/lib/ruby/2.5.0/rubygems.rb
36 /home/mame/local/lib/ruby/2.5.0/rubygems/path_support.rb
37 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean/version.rb
38 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean/core_ext/name_error.rb
39 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean/levenshtein.rb
40 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean/jaro_winkler.rb
41 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean/spell_checker.rb
42 /home/mame/local/lib/ruby/2.5.0/delegate.rb
43 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb
44 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean/spell_checkers/name_error_checkers/variable_name_checker.rb
45 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean/spell_checkers/name_error_checkers.rb
46 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean/spell_checkers/method_name_checker.rb
47 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean/spell_checkers/key_error_checker.rb
48 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean/spell_checkers/null_checker.rb
49 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean/formatters/plain_formatter.rb
50 /home/mame/local/lib/ruby/gems/2.5.0/gems/did_you_mean-1.2.0/lib/did_you_mean.rb
* Process memory map:
5569cb332000-5569cb65b000 r-xp 00000000 08:06 37880534 /home/mame/local/bin/ruby
5569cb85b000-5569cb860000 r--p 00329000 08:06 37880534 /home/mame/local/bin/ruby
5569cb860000-5569cb861000 rw-p 0032e000 08:06 37880534 /home/mame/local/bin/ruby
5569cb861000-5569cb871000 rw-p 00000000 00:00 0
5569cc0d8000-5569cc4ed000 rw-p 00000000 00:00 0 [heap]
7f6363028000-7f6363218000 r--s 00000000 08:06 46400127 /lib/x86_64-linux-gnu/libc-2.27.so
7f6363218000-7f63642b8000 r--s 00000000 08:06 37880534 /home/mame/local/bin/ruby
7f63642b8000-7f63642cf000 r-xp 00000000 08:06 46399538 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f63642cf000-7f63644ce000 ---p 00017000 08:06 46399538 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f63644ce000-7f63644cf000 r--p 00016000 08:06 46399538 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f63644cf000-7f63644d0000 rw-p 00017000 08:06 46399538 /lib/x86_64-linux-gnu/libgcc_s.so.1
7f63644d0000-7f63644d9000 r-xp 00000000 08:06 37922256 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/stringio.so
7f63644d9000-7f63646d8000 ---p 00009000 08:06 37922256 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/stringio.so
7f63646d8000-7f63646d9000 r--p 00008000 08:06 37922256 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/stringio.so
7f63646d9000-7f63646da000 rw-p 00009000 08:06 37922256 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/stringio.so
7f63646da000-7f63646dc000 r-xp 00000000 08:06 37922237 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/enc/trans/transdb.so
7f63646dc000-7f63648dc000 ---p 00002000 08:06 37922237 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/enc/trans/transdb.so
7f63648dc000-7f63648dd000 r--p 00002000 08:06 37922237 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/enc/trans/transdb.so
7f63648dd000-7f63648de000 rw-p 00003000 08:06 37922237 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/enc/trans/transdb.so
7f63648de000-7f63648e0000 r-xp 00000000 08:06 37921703 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/enc/encdb.so
7f63648e0000-7f6364adf000 ---p 00002000 08:06 37921703 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/enc/encdb.so
7f6364adf000-7f6364ae0000 r--p 00001000 08:06 37921703 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/enc/encdb.so
7f6364ae0000-7f6364ae1000 rw-p 00002000 08:06 37921703 /home/mame/local/lib/ruby/2.5.0/x86_64-linux/enc/encdb.so
7f6364ae1000-7f6364cc8000 r-xp 00000000 08:06 46400127 /lib/x86_64-linux-gnu/libc-2.27.so
7f6364cc8000-7f6364ec8000 ---p 001e7000 08:06 46400127 /lib/x86_64-linux-gnu/libc-2.27.so
7f6364ec8000-7f6364ecc000 r--p 001e7000 08:06 46400127 /lib/x86_64-linux-gnu/libc-2.27.so
7f6364ecc000-7f6364ece000 rw-p 001eb000 08:06 46400127 /lib/x86_64-linux-gnu/libc-2.27.so
7f6364ece000-7f6364ed2000 rw-p 00000000 00:00 0
7f6364ed2000-7f636506f000 r-xp 00000000 08:06 46400275 /lib/x86_64-linux-gnu/libm-2.27.so
7f636506f000-7f636526e000 ---p 0019d000 08:06 46400275 /lib/x86_64-linux-gnu/libm-2.27.so
7f636526e000-7f636526f000 r--p 0019c000 08:06 46400275 /lib/x86_64-linux-gnu/libm-2.27.so
7f636526f000-7f6365270000 rw-p 0019d000 08:06 46400275 /lib/x86_64-linux-gnu/libm-2.27.so
7f6365270000-7f6365279000 r-xp 00000000 08:06 46400226 /lib/x86_64-linux-gnu/libcrypt-2.27.so
7f6365279000-7f6365478000 ---p 00009000 08:06 46400226 /lib/x86_64-linux-gnu/libcrypt-2.27.so
7f6365478000-7f6365479000 r--p 00008000 08:06 46400226 /lib/x86_64-linux-gnu/libcrypt-2.27.so
7f6365479000-7f636547a000 rw-p 00009000 08:06 46400226 /lib/x86_64-linux-gnu/libcrypt-2.27.so
7f636547a000-7f63654a8000 rw-p 00000000 00:00 0
7f63654a8000-7f63654ab000 r-xp 00000000 08:06 46400231 /lib/x86_64-linux-gnu/libdl-2.27.so
7f63654ab000-7f63656aa000 ---p 00003000 08:06 46400231 /lib/x86_64-linux-gnu/libdl-2.27.so
7f63656aa000-7f63656ab000 r--p 00002000 08:06 46400231 /lib/x86_64-linux-gnu/libdl-2.27.so
7f63656ab000-7f63656ac000 rw-p 00003000 08:06 46400231 /lib/x86_64-linux-gnu/libdl-2.27.so
7f63656ac000-7f636572b000 r-xp 00000000 08:06 27265975 /usr/lib/x86_64-linux-gnu/libgmp.so.10.3.2
7f636572b000-7f636592b000 ---p 0007f000 08:06 27265975 /usr/lib/x86_64-linux-gnu/libgmp.so.10.3.2
7f636592b000-7f636592c000 r--p 0007f000 08:06 27265975 /usr/lib/x86_64-linux-gnu/libgmp.so.10.3.2
7f636592c000-7f636592d000 rw-p 00080000 08:06 27265975 /usr/lib/x86_64-linux-gnu/libgmp.so.10.3.2
7f636592d000-7f6365947000 r-xp 00000000 08:06 46400298 /lib/x86_64-linux-gnu/libpthread-2.27.so
7f6365947000-7f6365b46000 ---p 0001a000 08:06 46400298 /lib/x86_64-linux-gnu/libpthread-2.27.so
7f6365b46000-7f6365b47000 r--p 00019000 08:06 46400298 /lib/x86_64-linux-gnu/libpthread-2.27.so
7f6365b47000-7f6365b48000 rw-p 0001a000 08:06 46400298 /lib/x86_64-linux-gnu/libpthread-2.27.so
7f6365b48000-7f6365b4c000 rw-p 00000000 00:00 0
7f6365b4c000-7f6365b73000 r-xp 00000000 08:06 46400081 /lib/x86_64-linux-gnu/ld-2.27.so
7f6365c1e000-7f6365d26000 rw-p 00000000 00:00 0
7f6365d4a000-7f6365d6e000 r--s 00000000 08:06 46400298 /lib/x86_64-linux-gnu/libpthread-2.27.so
7f6365d6e000-7f6365d6f000 ---p 00000000 00:00 0
7f6365d6f000-7f6365d73000 rw-p 00000000 00:00 0
7f6365d73000-7f6365d74000 r--p 00027000 08:06 46400081 /lib/x86_64-linux-gnu/ld-2.27.so
7f6365d74000-7f6365d75000 rw-p 00028000 08:06 46400081 /lib/x86_64-linux-gnu/ld-2.27.so
7f6365d75000-7f6365d76000 rw-p 00000000 00:00 0
7ffdac1f9000-7ffdac9f8000 rw-p 00000000 00:00 0 [stack]
7ffdac9f9000-7ffdac9fc000 r--p 00000000 00:00 0 [vvar]
7ffdac9fc000-7ffdac9fe000 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
Aborted (core dumped)
Actions
Like0
Like0