changeset 10188:3de4322b3387

8047904: Runtime.loadLibrary throws SecurityException when security manager is installed Reviewed-by: alanb, psandoz
author mchung
date Tue, 24 Jun 2014 16:22:57 -0700
parents 60a73f4ccbe8
children fa193c3cae5b
files src/share/classes/java/lang/ClassLoader.java src/share/classes/sun/misc/Launcher.java
diffstat 2 files changed, 32 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/classes/java/lang/ClassLoader.java	Tue Jun 24 14:05:47 2014 -0700
+++ b/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/src/share/classes/sun/misc/Launcher.java	Tue Jun 24 14:05:47 2014 -0700
+++ b/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;