Bug #7423

ruby_process_options() dereferences argv even if argc is zero

Added by Graham Menhennitt over 1 year ago. Updated 12 months ago.

[ruby-core:49889]
Status:Closed
Priority:Low
Assignee:-
Category:-
Target version:-
ruby -v:ruby 1.9.3p327 (2012-11-10 revision 37606) [i686-linux] Backport:

Description

In rubyprocessoptions(), there is a line:

ruby_script(argv[0]);  /* for the time being */

This dereferences argv whether argc is zero or not. This causes a SEGV if there are no command line args. It should be changed to something like:

ruby_script(argc == 0 ? "ruby" : argv[0]);

In practice, this is unlikely to happen since shells never pass argc as zero. However, it can happen in two situations:
- a program calls something like 'static char argv[] = {0}; execv("/usr/bin/ruby", argv);'
- somebody embedding a ruby interpreter explicitly calls rubyprocessoptions(0, 0);

Argv is used in a number of other places too. These should all be tested for zero arguments.

Associated revisions

Revision 37823
Added by Nobuyoshi Nakada over 1 year ago

ruby.c: argv check

  • ruby.c (procoptions, processoptions, rubyprocessoptions): take care of the case argc is 0, and check if argv has NULL. [Bug #7423]

History

#1 Updated by Nobuyoshi Nakada over 1 year ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r37823.
Graham, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


ruby.c: argv check

  • ruby.c (procoptions, processoptions, rubyprocessoptions): take care of the case argc is 0, and check if argv has NULL. [Bug #7423]

#2 Updated by Roland Hautz 12 months ago

This bug fix is neither on the (complete) Roadmap nor reported under the "Bugs unassociated with any target version". I'm afraid it should be reopened in order to get on the radar for a release.

Also available in: Atom PDF