From 907cdc7fad039a88c619a92107186ef03b9a816f Mon Sep 17 00:00:00 2001 From: Michael Koch Date: Tue, 6 Jan 2004 08:34:58 +0000 Subject: [PATCH] 2004-01-06 Michael Koch * java/lang/Package.java (getPackage): Get the current class loader directly. * java/lang/SecurityManager.java (currentLoadedClass): Dont iterate over class contexts. (classLoaderDepth): Don't check class loaders if everything is allowed. From-SVN: r75465 --- libjava/ChangeLog | 8 ++++++++ libjava/java/lang/Package.java | 3 +-- libjava/java/lang/SecurityManager.java | 24 +++++++++++++++--------- 3 files changed, 24 insertions(+), 11 deletions(-) diff --git a/libjava/ChangeLog b/libjava/ChangeLog index f19dd30bfcba..c97afbc4084f 100644 --- a/libjava/ChangeLog +++ b/libjava/ChangeLog @@ -1,3 +1,11 @@ +2004-01-06 Michael Koch + + * java/lang/Package.java + (getPackage): Get the current class loader directly. + * java/lang/SecurityManager.java + (currentLoadedClass): Dont iterate over class contexts. + (classLoaderDepth): Don't check class loaders if everything is allowed. + 2004-01-05 Thomas Fitzsimmons * jni/gtk-peer/gnu_java_awt_peer_gtk_GtkEvents.c diff --git a/libjava/java/lang/Package.java b/libjava/java/lang/Package.java index f09814b6764d..3045b50c2f16 100644 --- a/libjava/java/lang/Package.java +++ b/libjava/java/lang/Package.java @@ -269,8 +269,7 @@ public class Package public static Package getPackage(String name) { // Get the caller's classloader - Class c = VMSecurityManager.getClassContext()[1]; - ClassLoader cl = c.getClassLoader(); + ClassLoader cl = VMSecurityManager.currentClassLoader(); return cl != null ? cl.getPackage(name) : null; } diff --git a/libjava/java/lang/SecurityManager.java b/libjava/java/lang/SecurityManager.java index e54ebc62f70e..bec39de1cd4d 100644 --- a/libjava/java/lang/SecurityManager.java +++ b/libjava/java/lang/SecurityManager.java @@ -207,11 +207,8 @@ public class SecurityManager */ protected Class currentLoadedClass() { - Class[] c = getClassContext(); - for (int i = 0; i < c.length; i++) - if (c[i].getClassLoader() != null) - return c[i]; - return null; + int i = classLoaderDepth(); + return i >= 0 ? getClassContext()[i] : null; } /** @@ -247,10 +244,18 @@ public class SecurityManager */ protected int classLoaderDepth() { - Class[] c = getClassContext(); - for (int i = 0; i < c.length; i++) - if (c[i].getClassLoader() != null) - return i; + try + { + checkPermission(new AllPermission()); + } + catch (SecurityException e) + { + Class[] c = getClassContext(); + for (int i = 0; i < c.length; i++) + if (c[i].getClassLoader() != null) + // XXX Check if c[i] is AccessController, or a system class. + return i; + } return -1; } @@ -1016,6 +1021,7 @@ public class SecurityManager for (int index = list.indexOf(packageName); index != -1; index = list.indexOf(packageName, index + 1)) { + // Exploit package visibility for speed. int packageNameCount = packageName.length(); if (index + packageNameCount == list.length() || list.charAt(index + packageNameCount) == ',')