To: vim_dev@googlegroups.com Subject: Patch 8.0.1448 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 8.0.1448 Problem: Segmentation fault when Ruby throws an exception inside :rubyfile command. Solution: Use rb_protect() instead of rb_load_protect(). (ujihisa, closes #2147, greywolf, closes #2512, #2511) Files: src/if_ruby.c, src/testdir/test_ruby.vim *** ../vim-8.0.1447/src/if_ruby.c 2017-10-28 21:08:38.983456981 +0200 --- src/if_ruby.c 2018-01-31 20:14:28.120021843 +0100 *************** *** 377,383 **** # endif static VALUE (*dll_rb_lastline_get) (void); static void (*dll_rb_lastline_set) (VALUE); ! static void (*dll_rb_protect) (VALUE (*)(VALUE), int, int*); static void (*dll_rb_load) (VALUE, int); static long (*dll_rb_num2long) (VALUE); static unsigned long (*dll_rb_num2ulong) (VALUE); --- 377,383 ---- # endif static VALUE (*dll_rb_lastline_get) (void); static void (*dll_rb_lastline_set) (VALUE); ! static VALUE (*dll_rb_protect) (VALUE (*)(VALUE), VALUE, int*); static void (*dll_rb_load) (VALUE, int); static long (*dll_rb_num2long) (VALUE); static unsigned long (*dll_rb_num2ulong) (VALUE); *************** *** 828,842 **** } } void ex_rubyfile(exarg_T *eap) { int state; if (ensure_ruby_initialized()) { ! rb_protect((VALUE (*)(VALUE))rb_load, rb_str_new2((char *)eap->arg), ! &state); ! if (state) error_print(state); } } --- 828,849 ---- } } + VALUE rb_load_wrap(VALUE file_to_load) + { + rb_load(file_to_load, 0); + return Qnil; + } + void ex_rubyfile(exarg_T *eap) { int state; if (ensure_ruby_initialized()) { ! VALUE file_to_load = rb_str_new2((const char *)eap->arg); ! rb_protect(rb_load_wrap, file_to_load, &state); ! if (state) ! error_print(state); } } *** ../vim-8.0.1447/src/testdir/test_ruby.vim 2017-01-29 23:11:21.172512839 +0100 --- src/testdir/test_ruby.vim 2018-01-31 20:11:21.429219954 +0100 *************** *** 49,51 **** --- 49,59 ---- bwipe! bwipe! endfunc + + func Test_rubyfile() + " Check :rubyfile does not SEGV with Ruby level exception but just fails + let tempfile = tempname() . '.rb' + call writefile(['raise "vim!"'], tempfile) + call assert_fails('rubyfile ' . tempfile) + call delete(tempfile) + endfunc *** ../vim-8.0.1447/src/version.c 2018-01-31 19:30:04.576336397 +0100 --- src/version.c 2018-01-31 20:14:50.051878051 +0100 *************** *** 773,774 **** --- 773,776 ---- { /* Add new patch number below this line */ + /**/ + 1448, /**/ -- The greatest lies of all time: (1) The check is in the mail. (2) We have a really challenging assignment for you. (3) I love you. (4) All bugs have been fixed. (5) This won't hurt a bit. (6) Honey, I just need to debug this program and be home in 5 minutes. (7) I have just sent you an e-mail about that. (8) Of course I'll respect you in the morning. (9) I'm from the government, and I'm here to help you. /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\ \\\ an exciting new programming language -- http://www.Zimbu.org /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///