8047904: Runtime.loadLibrary throws SecurityException when security manager is installed
authormchung
Tue, 24 Jun 2014 16:22:57 -0700
changeset 25167 6a8e55aba124
parent 25166 7fb4fe5b60e2
child 25168 6d5ac307bd8e
8047904: Runtime.loadLibrary throws SecurityException when security manager is installed Reviewed-by: alanb, psandoz
jdk/src/share/classes/java/lang/ClassLoader.java
jdk/src/share/classes/sun/misc/Launcher.java
--- a/jdk/src/share/classes/java/lang/ClassLoader.java	Tue Jun 24 14:05:47 2014 -0700
+++ b/jdk/src/share/classes/java/lang/ClassLoader.java	Tue Jun 24 16:22:57 2014 -0700
@@ -1859,18 +1859,17 @@
         String name = NativeLibrary.findBuiltinLib(file.getName());
         boolean isBuiltin = (name != null);
         if (!isBuiltin) {
-            boolean exists = AccessController.doPrivileged(
-                new PrivilegedAction<Object>() {
-                    public Object run() {
-                        return file.exists() ? Boolean.TRUE : null;
-                    }})
-                != null;
-            if (!exists) {
-                return false;
-            }
-            try {
-                name = file.getCanonicalPath();
-            } catch (IOException e) {
+            name = AccessController.doPrivileged(
+                new PrivilegedAction<String>() {
+                    public String run() {
+                        try {
+                            return file.exists() ? file.getCanonicalPath() : null;
+                        } catch (IOException e) {
+                            return null;
+                        }
+                    }
+                });
+            if (name == null) {
                 return false;
             }
         }
--- a/jdk/src/share/classes/sun/misc/Launcher.java	Tue Jun 24 14:05:47 2014 -0700
+++ b/jdk/src/share/classes/sun/misc/Launcher.java	Tue Jun 24 16:22:57 2014 -0700
@@ -207,7 +207,7 @@
          * look in the extension directory itself.
          */
         public String findLibrary(String name) {
-            name = System.mapLibraryName(name);
+            final String libname = System.mapLibraryName(name);
             URL[] urls = super.getURLs();
             File prevDir = null;
             for (int i = 0; i < urls.length; i++) {
@@ -216,17 +216,26 @@
                 if (dir != null && !dir.equals(prevDir)) {
                     // Look in architecture-specific subdirectory first
                     // Read from the saved system properties to avoid deadlock
-                    String arch = VM.getSavedProperty("os.arch");
-                    if (arch != null) {
-                        File file = new File(new File(dir, arch), name);
-                        if (file.exists()) {
-                            return file.getAbsolutePath();
-                        }
-                    }
-                    // Then check the extension directory
-                    File file = new File(dir, name);
-                    if (file.exists()) {
-                        return file.getAbsolutePath();
+                    final String arch = VM.getSavedProperty("os.arch");
+                    String pathname = AccessController.doPrivileged(
+                        new PrivilegedAction<String>() {
+                            public String run() {
+                                if (arch != null) {
+                                    File file = new File(new File(dir, arch), libname);
+                                    if (file.exists()) {
+                                        return file.getAbsolutePath();
+                                    }
+                                }
+                                // Then check the extension directory
+                                File file = new File(dir, libname);
+                                if (file.exists()) {
+                                    return file.getAbsolutePath();
+                                }
+                                return null;
+                            }
+                        });
+                    if (pathname != null) {
+                        return pathname;
                     }
                 }
                 prevDir = dir;