Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add tests for Kernel#spawn's chdir option #4263

Closed
wants to merge 1 commit into from

Conversation

seanfisk
Copy link

@seanfisk seanfisk commented Nov 3, 2016

First of all, thank you for all of your hard work on JRuby! It is very much appreciated.

It seems like some of the issues surrounding the current implementation of the chdir option to Kernel#spawn and friends are well-known (#985, #3653, #3655). I am aware that JRuby transitioned from Java's subprocess execution system to MRI's in recent releases, which was the source of some bugs. I am also aware of the concern associated with doing a native chdir in the JVM process.

Instead of just reporting an issue, I thought it would be helpful to add some [pending] tests that illustrate how the current behavior differs from MRI/the expected behavior. The two tests with pend fail in JRuby, while they pass in MRI 2.3.1 with flying colors (after removing pend).

The behavior of these functions when given the chdir option varies from MRI in the following ways:

  • JRuby always executes the command through the shell when given the chdir option. This is not appropriate because characters in a shell command have different meaning than those passed directly to exec and friends. For example, a shell expands $var, etc. while those characters retain literal meaning in exec. Kernel#spawn has a specific (albeit unnecessarily complex) contract as to when it will execute a command-line through the shell vs. directly, and chdir in JRuby overrides that.
  • JRuby currently surrounds the value of the chdir option with single quotes and inserts it into the command passed to the shell. Without too much effort, it is easy to achieve arbitrary code execution by injecting shell commands into the value of chdir. This is a possible security vulnerability, especially when the value of chdir is taken from user input.

I'm not sure of the best way to address these issues in the implementation. Per @headius's comments here, I think it would be worth giving native chdir a shot just to see what happens. I'd be happy to assist in implementation and testing with all the time I have available.

What do you think? Again, thank you for JRuby!

@seanfisk
Copy link
Author

seanfisk commented Nov 4, 2016

The first Travis build failure seems related to these new tests; not quite sure why the other Travis jobs are succeeding while this is failing, though. The second Travis failure and the Appveyor failures seem unrelated to the new tests, however.

@headius
Copy link
Member

headius commented Feb 26, 2021

This is quite old and we are now running the relevant CRuby and ruby/spec tests for this behavior.

@headius headius closed this Feb 26, 2021
@headius headius added this to the Invalid or Duplicate milestone Feb 26, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants