Skip to content

Possible forkbomb #23

@chetan

Description

@chetan

Hey,

I ran into a situation where I'm trying to require systemu directly on the command line like so:

RUBYOPT="-rsystemu" ./foo.rb

The following code from systemu.rb causes an infinite loop:

  c = begin; ::RbConfig::CONFIG; rescue NameError; ::Config::CONFIG; end
  ruby = File.join(c['bindir'], c['ruby_install_name']) << c['EXEEXT']
  @ruby = if system('%s -e 42' % ruby)
    ruby
  else
    system('%s -e 42' % 'ruby') ? 'ruby' : warn('no ruby in PATH/CONFIG')
  end

I'm not really sure what this is trying to do; make sure the initially detected ruby binary actually exists? Make sure it's actually ruby? Since the output isn't being verified, I'm not sure this is effective. I think a simple File.exists? test should be good enough, or else maybe this could be lazy loaded the first time the @ruby var is accessed?

I've created a simple test repo here to demonstrate the issue:

https://github.com/chetan/systemu_forkbomb

Simply run test.sh or test.rb and watch ps to see what happens. The only way to kill it is killall ruby.

chetan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions