Project

General

Profile

Actions

Bug #15887

closed

Process.argv0 can return bad values in Ruby 2.5

Added by joeym (Joey Marianer) over 5 years ago. Updated about 5 years ago.

Status:
Closed
Assignee:
-
Target version:
-
ruby -v:
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-darwin18]
[ruby-core:92884]

Description

MacOS 10.14.5 on a clean (source, using ruby-install) installation of Ruby 2.5.5

$ ruby --version
ruby 2.5.5p157 (2019-03-15 revision 67260) [x86_64-darwin18]
$ gem install vault vcr virtus webmock webrick
$ echo Process.argv0 | irb

...sometimes returns {}, sometimes some other nonsense and sometimes segfaults, but never (or rarely enough that I haven't seen it) returns a string ending in bin/irb as expected.

Unfortunately the bug only manifests when certain gems are installed; the set I included above is one possible set of gems that triggers the bug; I don't know what's special about it.

Updated by shevegen (Robert A. Heiler) over 5 years ago

Interesting. I just did Process.argv0 in irb and irb crashed right away.

If I put it into a .rb file it works fine. I haven't systematically tested
what causes the issue or whether my crash is related to the one here (I am
on linux for example), but perhaps others may also find some combination
that may cause Process.argv0 to lead to crash/segfaults.

Updated by alanwu (Alan Wu) over 5 years ago

Here's is a one line crasher: ruby -e '$0 = "hi"; 4.times { GC.start }; Process.argv0.class'
This crashes 2.5.5 and 2.6.3, but 2.4.6 seems to be immune. Bisect points to 478003f6df40dc79d33c6ec86919f2dde07284be.
I have a PR for this: https://github.com/ruby/ruby/pull/2213

Updated by jeremyevans0 (Jeremy Evans) over 5 years ago

  • Backport changed from 2.4: UNKNOWN, 2.5: UNKNOWN, 2.6: UNKNOWN to 2.4: DONTNEED, 2.5: REQUIRED, 2.6: REQUIRED

I've reviewed and tested the pull request and it appears to be the correct fix to me. I confirmed this does crash immediately on 2.5.5, 2.6.3, 2.7.0-preview1, and trunk, and the fix makes it no longer crash. This fix should be backported to 2.5 and 2.6.

Actions #4

Updated by alanwu (Alan Wu) over 5 years ago

  • Status changed from Open to Closed

Applied in changeset git|ea42423908ed055f9039b1dce6e9a232a3b2dd90.


Keep vm->orig_progname alive

vm->orig_progname can be different from vm->progname when user
code assigns to $0. While vm->progname is kept alive by the
global table, nothing marked vm->orig_progname.

[Bug #15887]

Updated by nagachika (Tomoyuki Chikanaga) over 5 years ago

  • Backport changed from 2.4: DONTNEED, 2.5: REQUIRED, 2.6: REQUIRED to 2.4: DONTNEED, 2.5: REQUIRED, 2.6: DONE

ruby_2_6 r67721 merged revision(s) ea42423908ed055f9039b1dce6e9a232a3b2dd90.

Updated by usa (Usaku NAKAMURA) about 5 years ago

  • Backport changed from 2.4: DONTNEED, 2.5: REQUIRED, 2.6: DONE to 2.4: DONTNEED, 2.5: DONE, 2.6: DONE

ruby_2_5 r67761 merged revision(s) ea42423908ed055f9039b1dce6e9a232a3b2dd90.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0Like0