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

RubyInstanceConfig#setupEnvironment throws AccessControlException on Windows #3220

Closed
hakanai opened this issue Aug 4, 2015 · 4 comments
Closed

Comments

@hakanai
Copy link

@hakanai hakanai commented Aug 4, 2015

Just trying to create a script engine:

    ScriptEngine engine = new JRubyEngineFactory().getScriptEngine();

fails with an AccessControlException in JRuby 9.0.0.0 on Windows:

java.security.AccessControlException: access denied ("java.io.FilePermission" "uri:classloader:\META-INF\jruby.home" "read")
    at java.security.AccessControlContext.checkPermission(AccessControlContext.java:457)
    at java.security.AccessController.checkPermission(AccessController.java:884)
    at java.lang.SecurityManager.checkPermission(SecurityManager.java:549)
    at java.lang.SecurityManager.checkRead(SecurityManager.java:888)
    at java.io.File.exists(File.java:814)
    at org.jruby.RubyInstanceConfig.setupEnvironment(RubyInstanceConfig.java:674)
    at org.jruby.RubyInstanceConfig.<init>(RubyInstanceConfig.java:123)
    at org.jruby.embed.internal.AbstractLocalContextProvider.getGlobalRuntimeConfigOrNew(AbstractLocalContextProvider.java:95)
    at org.jruby.embed.internal.SingletonLocalContextProvider.initLocalContext(SingletonLocalContextProvider.java:56)
    at org.jruby.embed.internal.SingletonLocalContextProvider.getProvider(SingletonLocalContextProvider.java:49)
    at org.jruby.embed.ScriptingContainer.getProviderInstance(ScriptingContainer.java:267)
    at org.jruby.embed.ScriptingContainer.<init>(ScriptingContainer.java:245)
    at org.jruby.embed.jsr223.JRubyEngineFactory.getScriptEngine(JRubyEngineFactory.java:170)

RubyInstanceConfig#setupEnvironment is calling File#exists but fails to catch the potential exception from this method:

private void setupEnvironment(String jrubyHome) {
    if (!new File(jrubyHome).exists() && !environment.containsKey("RUBY")) {
        ...
    }
}

But in this situation, jrubyHome isn't even a file path, it's a URI.

I could add a quick check here that the path doesn't start with "uri:", but it isn't clear what the correct behaviour should be in this situation. Should the code be properly checking that the URI exists?

@kares
Copy link
Member

@kares kares commented Aug 4, 2015

@mkristian
Copy link
Member

@mkristian mkristian commented Aug 4, 2015

having a positive check for a uri-like path using something like https://github.com/jruby/jruby/blob/master/core/src/main/java/org/jruby/RubyFile.java#L637
seems better suited. the check is meant to determine whether jruby gets executed from within a jar or not.

@kares
Copy link
Member

@kares kares commented Aug 4, 2015

OK, that PATTERN matching could be shared at package level ... was mostly interested in avoiding the (anticipated) regression the commit(s) has introduced but if you're to change that to avoid the new File anyways its all yours ... please fix it on 1.7 as well, thanks

mkristian added a commit that referenced this issue Aug 4, 2015
this fixes issue #3220

Sponsored by Lookout Inc.
@headius headius added this to the JRuby 9.0.1.0 milestone Aug 6, 2015
@kares
Copy link
Member

@kares kares commented Aug 6, 2015

fixed both at jruby-1_7 and master ... by @mkristian

@kares kares closed this Aug 6, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants