Issue Type: Bug Bug
Affects Versions: JRuby 1.7.0.pre1
Assignee: Thomas E Enebo
Created: 06/Aug/12 5:06 AM
Description:

Kernel.exec, Process.spawn (and related methods such as IO.popen) raise error when program is an array containing two String objects.

for example,

% jruby -v -e 'exec(["/bin/ls", "XXX"])'
jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java]
Errno::ENOENT: No such file or directory - XXX
_exec_internal at org/jruby/RubyKernel.java:1612
exec at file:/PPPPPPP/jruby-1.7.0.preview1/lib/jruby.jar!/jruby/kernel19/kernel.rb:23
(root) at -e:1

% jruby -v -e 'Process.waitpid Process.spawn(["/bin/ls", "XXX"])'
jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java]
Errno::ENOENT: No such file or directory - XXX
_spawn_internal at org/jruby/RubyProcess.java:992
spawn at file:/PPPPPPP/jruby-1.7.0.preview1/lib/jruby.jar!/jruby/kernel19/process.rb:3
(root) at -e:1

% jruby -v -e 'print IO.popen([["/bin/ls", "XXX"]], "r+") { |io| io.read }'
jruby 1.7.0.preview1 (ruby-1.9.3-p203) (2012-05-19 00c8c98) (OpenJDK 64-Bit Server VM 1.6.0_20) [linux-amd64-java]
TypeError: can't convert Array into String
popen at org/jruby/RubyIO.java:3813
(root) at -e:1


In MRI, all of the above works. (Note that Process.spawn and IO.popen with this style are supported since Ruby 1.9.)

% ruby187 -v -e 'exec(["/bin/ls", "XXX"])'
ruby 1.8.7 (2010-08-16 patchlevel 302) [x86_64-linux]
(result of /bin/ls is displayed)

% ruby -v -e 'Process.waitpid Process.spawn(["/bin/ls", "XXX"])'
ruby 1.9.3p253 (2012-07-04) [x86_64-linux]
(result of /bin/ls is displayed)

% ruby -v -e 'print IO.popen([["/bin/ls", "XXX"]], "r+") { |io| io.read }'
ruby 1.9.3p253 (2012-07-04) [x86_64-linux]
(result of /bin/ls is displayed)

In MRI, when the program is an array containing two String objects, the first element of the array is executed, and the second element is used for the display name.

This style is used when executing a program with no arguments without invoking the shell. This is useful to avoid potential security problem related with white speces and shell special characters.

% ruby -v -e 'exec("ls -l")'
ruby 1.9.3p253 (2012-07-04) [x86_64-linux]
(result of "ls -l" is displayed)

% ruby -v -e 'exec(["ls -l", "XXX"])'
ruby 1.9.3p253 (2012-07-04) [x86_64-linux]
-e:1:in `exec': No such file or directory - ls -l (Errno::ENOENT)
from -e:1:in `<main>'

Project: JRuby
Priority: Major Major
Reporter: Naohisa Goto
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators.
For more information on JIRA, see: http://www.atlassian.com/software/jira
--------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email

Reply via email to