8047904: Runtime.loadLibrary throws SecurityException when security manager is installed

Reviewed-by: alanb, psandoz
This commit is contained in:
Mandy Chung 2014-06-24 16:22:57 -07:00
parent 0caae2d748
commit bfe7a7abd1
2 changed files with 32 additions and 24 deletions

View File

@ -1859,18 +1859,17 @@ public abstract class ClassLoader {
String name = NativeLibrary.findBuiltinLib(file.getName()); String name = NativeLibrary.findBuiltinLib(file.getName());
boolean isBuiltin = (name != null); boolean isBuiltin = (name != null);
if (!isBuiltin) { if (!isBuiltin) {
boolean exists = AccessController.doPrivileged( name = AccessController.doPrivileged(
new PrivilegedAction<Object>() { new PrivilegedAction<String>() {
public Object run() { public String run() {
return file.exists() ? Boolean.TRUE : null; try {
}}) return file.exists() ? file.getCanonicalPath() : null;
!= null; } catch (IOException e) {
if (!exists) { return null;
return false; }
} }
try { });
name = file.getCanonicalPath(); if (name == null) {
} catch (IOException e) {
return false; return false;
} }
} }

View File

@ -207,7 +207,7 @@ public class Launcher {
* look in the extension directory itself. * look in the extension directory itself.
*/ */
public String findLibrary(String name) { public String findLibrary(String name) {
name = System.mapLibraryName(name); final String libname = System.mapLibraryName(name);
URL[] urls = super.getURLs(); URL[] urls = super.getURLs();
File prevDir = null; File prevDir = null;
for (int i = 0; i < urls.length; i++) { for (int i = 0; i < urls.length; i++) {
@ -216,17 +216,26 @@ public class Launcher {
if (dir != null && !dir.equals(prevDir)) { if (dir != null && !dir.equals(prevDir)) {
// Look in architecture-specific subdirectory first // Look in architecture-specific subdirectory first
// Read from the saved system properties to avoid deadlock // Read from the saved system properties to avoid deadlock
String arch = VM.getSavedProperty("os.arch"); final String arch = VM.getSavedProperty("os.arch");
if (arch != null) { String pathname = AccessController.doPrivileged(
File file = new File(new File(dir, arch), name); new PrivilegedAction<String>() {
if (file.exists()) { public String run() {
return file.getAbsolutePath(); if (arch != null) {
} File file = new File(new File(dir, arch), libname);
} if (file.exists()) {
// Then check the extension directory return file.getAbsolutePath();
File file = new File(dir, name); }
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; prevDir = dir;