Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@ujihisa
Copy link

@ujihisa ujihisa commented Sep 23, 2017

Short summary: fix a segv for if_ruby.

Problem

Vim with +ruby causes segmentation fault when Ruby throws an exception inside :rubyfile command.

echo 'raise' > /tmp/raise.rb
vim -u NONE -N -c 'rubyfile /tmp/raise.rb'

I tested with Vim 7.3.939, 8.0.0000, latest 8.0.1139, with Ruby 2.3.1, 2.4.2, and latest 2.5.0dev. I don't know when exactly happened, but it must have been happening since pretty old version.

This is likely a Ruby bug, since rb_load_protect is supposed to be used to avoid segmentation fault, according to a third-party doc.a Ruby committer also suggested it may be a Ruby bug.

Solution

I took a workaround. According to existing :h rubyfile, the updated behaviour should be straightforward.

For long-term solution, Ruby should fix the function itself. Vim supports older versions of Ruby, so the above solution should be better.

Acknowledgement

Thanks @pocke to report this issue at vim-jp/issues#1098, and @mattn to help me a lot contributing to vim core for the first time! Also thanks indirectly to @nurse confirming it's likely a Ruby bug.

@codecov-io
Copy link

codecov-io commented Sep 23, 2017

Codecov Report

Merging #2147 into master will increase coverage by 0.01%.
The diff coverage is 100%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #2147      +/-   ##
==========================================
+ Coverage   73.96%   73.98%   +0.01%     
==========================================
  Files          90       90              
  Lines      131906   131908       +2     
  Branches    28964    28965       +1     
==========================================
+ Hits        97570    97592      +22     
+ Misses      34313    34297      -16     
+ Partials       23       19       -4
Impacted Files Coverage Δ
src/if_ruby.c 60.78% <100%> (+4.32%) ⬆️
src/term.c 51.23% <0%> (-0.22%) ⬇️
src/message.c 68.26% <0%> (-0.2%) ⬇️
src/window.c 81.65% <0%> (-0.1%) ⬇️
src/gui.c 46.34% <0%> (ø) ⬆️
src/evalfunc.c 82.85% <0%> (+0.03%) ⬆️
src/channel.c 82.63% <0%> (+0.08%) ⬆️
src/gui_gtk_x11.c 47.86% <0%> (+0.1%) ⬆️
src/if_py_both.h 76.23% <0%> (+0.14%) ⬆️
src/if_xcmdsrv.c 84.89% <0%> (+1.07%) ⬆️
... and 1 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 0b05e49...a96452a. Read the comment docs.

@nurse
Copy link

nurse commented Sep 27, 2017

This issue is fixed by ruby/ruby@d352d0a, and will be backported on next 2.3/2.4 stable release.

@brammool
Copy link
Contributor

This works for static linking, but not when using ruby/dynamic

@brammool
Copy link
Contributor

Stack trace when Vim crashes:
(gdb) where
#0 0x00007fffed97ab9b in () at /usr/lib/x86_64-linux-gnu/libruby-2.3.so.2.3
#1 0x00007fffed97ad10 in () at /usr/lib/x86_64-linux-gnu/libruby-2.3.so.2.3
#2 0x00007fffed972f2e in () at /usr/lib/x86_64-linux-gnu/libruby-2.3.so.2.3
#3 0x00007fffed973a58 in rb_load ()
at /usr/lib/x86_64-linux-gnu/libruby-2.3.so.2.3
#4 0x00007fffed97006b in rb_protect ()
at /usr/lib/x86_64-linux-gnu/libruby-2.3.so.2.3
#5 0x00005555557f80e3 in ex_rubyfile (eap=0x7fffffffbb70) at if_ruby.c:837

that is at this command:
rb_protect((VALUE (*)(VALUE))rb_load, rb_str_new2((char *)eap->arg),
&state);

@k-takata
Copy link
Member

@brammool It looks that this is merged as a part of 8.0.1236.
Is this intended? If so, we can close this PR, and I think @ujihisa's name should be credited in the patch (when you update version8.txt).

@nuko8
Copy link

nuko8 commented Oct 30, 2017

I'd like to definitely decline the proposal of co-authorship.

If things should be settled like that, that is, through my accepting co-authorship, then that must sound as if I stole this PR, smuggled it into master via my own PR #2178, and approved such an terrible allegation against me afterwards.

As clearly shown in the commit log of #2178, I'm not guilty. Accordingly, there's no reason at all for me to accept such a ridiculous proposal. How can I be in favor of the patch of this PR at the cost of my honor? No way.

Furthermore, the proposed patch of this PR has already been labeled "incomplete" via a message to vim_dev. I'm wondering how come it's possible for someone to think the inclusion intended. I would say that must have took place accidentally. Naturally, a decent solution to that is crystal clear to everyone: Remove that Ruby part from 8.0.1236 and make the latter clean.

@k-takata
Copy link
Member

I agree that this PR is totally unrelated to #2178, so adding his name to 8.0.1236 is confusing and/or misleading.
Creating a separate patch for this would be better if Bram really intended to include this.

I'm not guilty.

Of course I know. So I'm asking to Bram, not to you.

@nuko8
Copy link

nuko8 commented Oct 30, 2017

Comparing the current if_ruby.c with the patch of this PR, I saw the Ruby part of 8.0.1236 including more changes than those proposed here. Rather, they appear to be identical with those found in this message, which I quoted previously.

Seems like there's been another patch different from this PR's. I'm wondering how the former is related to the latter in terms of authorship, though I actually don't care about that.

@mattn
Copy link
Member

mattn commented Oct 30, 2017

We understand and strongly believe this is simply mistake of commit. And we are thinking contributor's name should be credited in the the patch files. For the contributors, what their name is credited in the patch file is proud things for themselves. :)

@chrisbra
Copy link
Member

I am sorry, I did not follow the whole conversation. Is there anything to be done here?

@k-takata
Copy link
Member

It's all up to Bram. Possible choices might be:

  • If Bram didn't intend to include the change to if_ruby.c:
    Create a new commit to revert the change and,
    • Create a new patch file (on the ftp server), or
    • Modify the patch 8.0.1236 and remove the change from it.
  • If the change is intended, make the change clearer and give a proper credit:
    • For the patch files:
      • Modify the patch 8.0.1236 and move the change into a new patch, or
      • Keep 8.0.1236 as it is, create a new patch to revert the change, and create another patch to include the change again.
    • For the git repository:
      • Keep as it is, or
      • Create a new commit to revert the change, and create another commit to include the change again.

@brammool
Copy link
Contributor

brammool commented Oct 31, 2017 via email

@brammool
Copy link
Contributor

brammool commented Oct 31, 2017 via email

@ujihisa
Copy link
Author

ujihisa commented Nov 28, 2017

Thanks for Bram to merge, and nurse, k-takata, and mattn for catching that up. As Bram mentioned that I confirmed that it still crashes with --enable-rubyinterp=dynamic. I didn't find any solutions for that yet.

# sorry for extremely late reply. I was focusing on VimConf last month and I forgot replying at all..

@brammool brammool closed this in 37badc8 Jan 31, 2018
@ujihisa
Copy link
Author

ujihisa commented Jan 31, 2018

Thanks a lot!

adizero pushed a commit to adizero/vim that referenced this pull request May 19, 2018
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim#2147, greywolf, closes vim#2512, vim#2511)
janlazo added a commit to janlazo/neovim that referenced this pull request Nov 17, 2018
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim/vim#2147, greywolf, closes vim/vim#2512, vim/vim#2511)
vim/vim@37badc8
janlazo added a commit to janlazo/neovim that referenced this pull request Nov 18, 2018
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim/vim#2147, greywolf, closes vim/vim#2512, vim/vim#2511)
vim/vim@37badc8
janlazo added a commit to janlazo/neovim that referenced this pull request Dec 28, 2018
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim/vim#2147, greywolf, closes vim/vim#2512, vim/vim#2511)
vim/vim@37badc8
janlazo added a commit to janlazo/neovim that referenced this pull request Dec 28, 2018
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim/vim#2147, greywolf, closes vim/vim#2512, vim/vim#2511)
vim/vim@37badc8
janlazo added a commit to janlazo/neovim that referenced this pull request Dec 31, 2018
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim/vim#2147, greywolf, closes vim/vim#2512, vim/vim#2511)
vim/vim@37badc8
janlazo added a commit to janlazo/neovim that referenced this pull request Apr 12, 2019
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim/vim#2147, greywolf, closes vim/vim#2512, vim/vim#2511)
vim/vim@37badc8
janlazo added a commit to janlazo/neovim that referenced this pull request Apr 25, 2019
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim/vim#2147, greywolf, closes vim/vim#2512, vim/vim#2511)
vim/vim@37badc8
janlazo added a commit to janlazo/neovim that referenced this pull request May 25, 2019
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim/vim#2147, greywolf, closes vim/vim#2512, vim/vim#2511)
vim/vim@37badc8
janlazo added a commit to janlazo/neovim that referenced this pull request Jun 8, 2019
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim/vim#2147, greywolf, closes vim/vim#2512, vim/vim#2511)
vim/vim@37badc8
janlazo added a commit to janlazo/neovim that referenced this pull request Jul 4, 2019
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim/vim#2147, greywolf, closes vim/vim#2512, vim/vim#2511)
vim/vim@37badc8
janlazo added a commit to janlazo/neovim that referenced this pull request Aug 23, 2019
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim/vim#2147, greywolf, closes vim/vim#2512, vim/vim#2511)
vim/vim@37badc8
janlazo added a commit to janlazo/neovim that referenced this pull request Sep 14, 2019
Problem:    Segmentation fault when Ruby throws an exception inside :rubyfile
            command.
Solution:   Use rb_protect() instead of rb_load_protect(). (ujihisa,
            closes vim/vim#2147, greywolf, closes vim/vim#2512, vim/vim#2511)
vim/vim@37badc8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants