コード例 #1
0
ファイル: LoadService.java プロジェクト: slagyr/jruby
  public void init(List additionalDirectories) {
    loadPath = RubyArray.newArray(runtime);
    loadedFeatures = RubyArray.newArray(runtime);
    loadedFeaturesInternal = Collections.synchronizedList(loadedFeatures);

    // add all startup load paths to the list first
    for (Iterator iter = additionalDirectories.iterator(); iter.hasNext(); ) {
      addPath((String) iter.next());
    }

    // add $RUBYLIB paths
    RubyHash env = (RubyHash) runtime.getObject().fastGetConstant("ENV");
    RubyString env_rubylib = runtime.newString("RUBYLIB");
    if (env.has_key_p(env_rubylib).isTrue()) {
      String rubylib = env.op_aref(runtime.getCurrentContext(), env_rubylib).toString();
      String[] paths = rubylib.split(File.pathSeparator);
      for (int i = 0; i < paths.length; i++) {
        addPath(paths[i]);
      }
    }

    // wrap in try/catch for security exceptions in an applet
    if (!Ruby.isSecurityRestricted()) {
      try {
        String jrubyHome = runtime.getJRubyHome();
        if (jrubyHome != null) {
          char sep = '/';
          String rubyDir = jrubyHome + sep + "lib" + sep + "ruby" + sep;

          // If we're running in 1.9 compat mode, add Ruby 1.9 libs to path before 1.8 libs
          if (runtime.is1_9()) {
            addPath(rubyDir + "site_ruby" + sep + Constants.RUBY1_9_MAJOR_VERSION);
            addPath(rubyDir + "site_ruby" + sep + "shared");
            addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION);
            addPath(rubyDir + Constants.RUBY1_9_MAJOR_VERSION);
          } else {
            // Add 1.8 libs
            addPath(rubyDir + "site_ruby" + sep + Constants.RUBY_MAJOR_VERSION);
            addPath(rubyDir + "site_ruby" + sep + "shared");
            addPath(rubyDir + Constants.RUBY_MAJOR_VERSION);
          }
        }
      } catch (SecurityException e) {
      }
    }

    // "." dir is used for relative path loads from a given file, as in require '../foo/bar'
    if (runtime.getSafeLevel() == 0) {
      addPath(".");
    }
  }
コード例 #2
0
ファイル: Util.java プロジェクト: jlieske/jruby
 public static final void checkStringSafety(Ruby runtime, IRubyObject value) {
   RubyString s = value.asString();
   if (runtime.getSafeLevel() > 0 && s.isTaint()) {
     throw runtime.newSecurityError("Unsafe string parameter");
   }
   ByteList bl = s.getByteList();
   final byte[] array = bl.unsafeBytes();
   final int end = bl.length();
   for (int i = bl.begin(); i < end; ++i) {
     if (array[i] == (byte) 0) {
       throw runtime.newSecurityError("string contains null byte");
     }
   }
 }
コード例 #3
0
ファイル: Tempfile.java プロジェクト: rkh/jruby
 private IRubyObject defaultTmpDir(Ruby runtime, IRubyObject[] args) {
   IRubyObject dir = null;
   if (args.length == 2) {
     dir = args[1];
   } else {
     // Dir::tmpdir
     runtime.getLoadService().require("tmpdir");
     dir = runtime.getDir().callMethod(runtime.getCurrentContext(), "tmpdir");
   }
   if (runtime.getSafeLevel() > 0 && dir.isTaint()) {
     dir = runtime.newString(DEFAULT_TMP_DIR);
   }
   return dir;
 }
コード例 #4
0
ファイル: RubyBasicSocket.java プロジェクト: vvs/jruby
  @Override
  public IRubyObject close_read(ThreadContext context) {
    Ruby runtime = context.getRuntime();
    if (runtime.getSafeLevel() >= 4 && isTaint()) {
      throw runtime.newSecurityError("Insecure: can't close");
    }

    if (!openFile.isOpen()) {
      throw context.getRuntime().newIOError("not opened for reading");
    }

    if (!openFile.isWritable()) {
      close();
    } else {
      // shutdown read
      shutdownInternal(context, 0);
    }
    return runtime.getNil();
  }